본문 바로가기

언어 꿀Tip/SQL

10_03. 연속적인 숫자 생성 Recursive CTE 사용

Recursive CTE 개념

Recursive CTE (Common Table Expression)는 CTE 중 자기 자신을 반복적으로 호출하는 CTE이다.

with recursive temp as
(
select 0 as trans_cnt
from transactions
union 
select trans_cnt+1
from temp
where trans_cnt < (
                    select count(*)
                    from transactions
                    group by user_id, transaction_date
                    order by 1 desc limit 1)
)