[ORACLE_SQL](Leet_Code) 1193. Monthly Transactions I

이경영·2023년 7월 26일
0

오라클

목록 보기
32/43

https://leetcode.com/problems/monthly-transactions-i/description/?envType=study-plan-v2&envId=top-sql-50

select to_char(trans_date, 'yyyy-mm') as month, 
       country,
       count(*) as trans_count,
       sum(case when state='approved' then 1 else 0 end )as approved_count,
       sum(amount) as trans_total_amount,
       sum(case when state='approved' then amount else 0 end) as approved_total_amount
from transactions
group by to_char(trans_date, 'yyyy-mm'), country
order by month , country desc

알게된것

  • case when 과 sum의 콜라보가 중요!
  • then 뒤에는 컬럼명도 올수가 있다
  • 생각보다 어렵지 않았던 문제
profile
꾸준히

0개의 댓글