작성
·
179
0
총매출/연매출/월매출을 구분하기 위해 case when 구문을 사용하셨는데
연/월 매출을 구할 때 수업 내 쿼리처럼 else를 다중으로 적는 것이 아닌
and로 else를 축약해도 쿼리상 문제가 없는지 궁금합니다.
with cte1 as (select to_char(order_date,'yyyy') as year
, to_char(order_date, 'mm') as month
, to_char(order_date, 'dd') as day
,sum(b.amount) as sum_amount
from orders as a
join order_items as b on a.order_id = b.order_id
group by rollup (1,2,3)
order by 1,2,3
)
select case when year is null then '총 매출' else year end as year
, case when year is not null and month is null then '년 매출' else month end as month
, case when year is not null and month is not null and day is null then '월 매출' else day end as day
,sum_amount
from cte1