Run Code

API

Code Wall

Users

Misc

Feedback

Login

Theme

Privacy

Patreon
SQL primes, sqrt sieve
with recursive N as ( select 100000 as N ), lim as ( select (select N from N) as m, sqrt((select N from N))::int as sqrtm ), p(n,step) as ( values(5,2) union all select n + step, step # 6 from p where n + step < (select m + 1 from lim) ), sp(sn,step) as ( values(5,2) union all select sn + step, step # 6 from sp where sn + step < (select sqrtm from lim) ), k as ( select i from generate_series(0,(select m / 5 from lim),2) s(i) ), sieve as ( select sn * sn + i * sn as v from sp inner join k on sn * sn + i * sn < (select m + 1 from lim) ), primes as ( select 2 as n union all select 3 union all select n from p except select * from sieve order by n ) select count(*) from primes;
run

edit

history

help
0
Please
log in
to post a comment.
1
1127. User Purchase Platform
Limit & union
Movie Rating SQL Analysis Conducted by Miranda Zhao
Query workaround in order to avoid IN Operator in WHERE Clause
mandelbrot set
Ass2 q2
renaming JSON field
Return IDs where there are exactly 3 occurrences
base de datos api teclab
Please log in to post a comment.