설명없음
[StrataScratch] Highest Cost Orders [MySQL]
치킨먹고싶어요
2022. 6. 26. 23:15
https://platform.stratascratch.com/coding/9915-highest-cost-orders?code_type=3
StrataScratch
platform.stratascratch.com
WITH CTE AS (
SELECT cust_id, SUM(total_order_cost) AS total, order_date
FROM orders
WHERE DATE(order_date) BETWEEN '2019-02-01' AND '2019-05-01'
GROUP BY cust_id, order_date
)
SELECT first_name, CTE.total, CTE.order_date
FROM customers
JOIN CTE
ON customers.id = CTE.cust_id
GROUP BY CTE.cust_id, CTE.order_date
ORDER BY CTE.total DESC
LIMIT 1;
|
cs |