0
点赞
收藏
分享

微信扫一扫

LeetCode(数据库)- 每位顾客最经常订购的商品


题目链接:​​点击打开链接​​

题目大意:略。

解题思路:略。

AC 代码

WITH t AS(SELECT customer_id, product_id, COUNT(*) cnt FROM Orders GROUP BY customer_id, product_id),

tt AS(SELECT customer_id, product_id, RANK() OVER(PARTITION BY customer_id ORDER BY cnt DESC) drk FROM t)

SELECT customer_id, tt.product_id, product_name
FROM tt JOIN Products USING(product_id)
WHERE drk = 1


举报

相关推荐

0 条评论