언어

recursive & repeat

땅호720 2024. 6. 25. 13:50
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  -- 나누어떨어지는 수 제외
)