LeetCode刷题-数据库(MySQL)- 1068. Product Sales Analysis I

本文介绍了LeetCode第1068题——Product Sales Analysis I,解析了题目要求,提供了思路分析及MySQL的代码实现,帮助理解如何从Sales和Product表中获取产品名称、销售年份和价格。
摘要由CSDN通过智能技术生成

1068. Product Sales Analysis I

一、题目描述

Table: Sales

Column NameType
sale_idint
product_idint
yearint
quantityint
priceint

(sale_id, year) is the primary key of this table.
product_id is a foreign key to Product table.
Note that the price is per unit.

Table: Product

Column NameType
product_idint
product_namevarchar

product_id is the primary key of this table.

Write an SQL query that reports all product names of the products in the Sales table along with their selling year and price.

For example:

Sales table:

sale_idproduct_idyearquantityprice
11002008105000
21002009125000
72002011159000

Product table:

product_idproduct_name
100Nokia
200Apple
300Samsung

Result table:

product_nameyearprice
Nokia20085000
Nokia20095000
Apple20119000

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

二、思路分析

直接两表内连接即可

三、代码实现

SELECT
	p.product_name, 
	s.year, 
	s.price
FROM
	Sales s
JOIN
	Product p
ON s.product_id = p.product_id;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值