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

阅读 88

2022-05-18


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

题目大意:略。

解题思路:略。

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)

0 0 举报