1596.(Medium)每位顾客最经常订购的商品
表:Customers
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| customer_id | int |
| name | varchar |
+---------------+---------+
customer_id 是该表主键
该表包含所有顾客的信息表:Orders
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| order_id | int |
| order_date | date |
| customer_id | int |
| product_id | int |
+---------------+---------+
order_id 是该表主键
该表包含顾客 customer_id 的订单信息
没有顾客会在一天内订购相同的商品 多于一次表:Products
写一个 SQL 语句,找到每一个顾客最经常订购的商品。
结果表单应该有每一位至少下过一次单的顾客 customer_id , 他最经常订购的商品的 product_id 和 product_name。
返回结果 没有顺序要求。
查询结果格式如下例所示:
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/the-most-frequently-ordered-products-for-each-customer
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
Solution
Last updated
Was this helpful?