代码拉取完成,页面将自动刷新
# Time: O(n)
# Space: O(n)
WITH product_count_cte AS
(SELECT c.customer_id,
o.product_id,
p.product_name,
count(c.customer_id) AS product_cnt
FROM Customers c,
Orders o,
Products p
WHERE c.customer_id = o.customer_id
AND o.product_id = p.product_id
GROUP BY c.customer_id,
o.product_id
ORDER BY NULL)
, max_product_count_cte AS
(SELECT customer_id,
max(product_cnt) AS product_cnt
FROM product_count_cte
GROUP BY customer_id
ORDER BY NULL)
SELECT a.customer_id,
a.product_id,
a.product_name
FROM product_count_cte a
INNER JOIN max_product_count_cte b
ON a.customer_id = b.customer_id AND
a.product_cnt = b.product_cnt;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。