https://solvesql.com/problems/shoppingmall-monthly-summary/
SELECT
SUBSTR(o.order_id, 1, 7) order_month,
sum(case when o.order_id not like 'C%' then i.quantity*i.price else 0 end) ordered_amount,
sum(case when o.order_id like 'C%' then i.quantity*i.price else 0 end) canceled_amount,
sum(i.quantity*i.price) total_amount
FROM order_items i
INNER JOIN orders o
on i.order_id = o.order_id
GROUP BY order_month
ORDER BY order_month;
[오늘의 코드 147] [SOLVESQL] 서울숲 요일별 대기오염도 계산하기 (0) | 2024.12.22 |
---|---|
[오늘의 코드 146] [SOLVESQL] 최대값을 가진 행 찾기 (0) | 2024.12.19 |
[오늘의 코드 144] [SOLVESQL] 기증품 비율 계산하기 (1) | 2024.12.11 |
[오늘의 코드 143] [SOLVESQL] 게임을 10개 이상 발매한 퍼블리셔 찾기 (0) | 2024.12.10 |
[오늘의 코드 142] [SOLVESQL] 언더스코어(_)가 포함되지 않은 데이터 찾기 (1) | 2024.12.09 |