• + 1 comment
    with recursive tmp as (
        select 2 as num
        union all
        select num + 1
        from tmp
        where num <= 1000
    )
    , primes as (
        select num
        from tmp as t1
        where not exists (select 1 
                          from tmp as t2
                          where t2.num < t1.num and t1.num % t2.num = 0)
    )
    select group_concat(num separator '&') from primes;