본문 바로가기
언어

recursive & repeat

by 땅호720 2024. 6. 25.
with recursive cte as (
    select 20 as NUM
    union all
    select NUM-1 from CTE
    where NUM > 0
)

select repeat('* ', NUM)
from cte

 

 

with recursive cte as (
select 1 as NUM
union all
select NUM+1 from cte
where NUM < 20)

select repeat('* ', NUM)
from cte

 

 

with recursive cte as (
select 2 as NUM
union all
select NUM+1
from cte
where NUM < 1000)

select group_concat(NUM separator '&')
from cte
where not exists (
    select *    -- NUM
    from cte as cte2
    where cte2.NUM <= sqrt(cte.NUM) -- 루트 NUM 이하 수 중에
        and cte.NUM % cte2.NUM = 0  -- 나누어떨어지는 수 제외
)

'언어' 카테고리의 다른 글

percent_rank, ntile  (0) 2024.07.08
비트연산  (0) 2024.07.02
interviews  (0) 2024.06.20
Symmetric Pairs  (0) 2024.06.19
with as  (0) 2024.06.18