力扣1068(MySQL)-产品销售分析Ⅰ(简单)

发布时间 2023-04-08 09:25:07作者: 我不想一直当菜鸟

题目:

销售表 Sales

 产品表 Product

写一条SQL 查询语句获取 Sales 表中所有产品对应的 产品名称 product_name 以及该产品的所有 售卖年份 year 和 价格 price 。

查询结果中的顺序无特定要求。

查询结果格式示例如下:

 

来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/product-sales-analysis-i
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

解题思路:

建表语句:

1 Create table if not exists Sales_1068 (sale_id int(3), product_id int(3), year int(3), quantity int(3), price int(3));
2 Create table if not exists Product_1068 (product_id int(3), product_name varchar(10));
3 Truncate table Sales_1068;
4 insert into Sales_1068 (sale_id, product_id, year, quantity, price) values ('1', '100', '2008', '10', '5000'),('2', '100', '2009', '12', '5000'),('7', '200', '2011', '15', '9000');
5 Truncate table Product_1068;
6 insert into Product_1068 (product_id, product_name) values ('100', 'Nokia'),('200', 'Apple'),('300', 'Samsung');

表联结