Advertisement
klippa

Prime numbers

Aug 19th, 2022
756
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. WITH RECURSIVE cte1 AS (
  2.   SELECT
  3.     2 AS val
  4.   UNION
  5.   ALL
  6.   SELECT
  7.     val + 1 AS val
  8.   FROM
  9.     cte1
  10.   WHERE
  11.     cte1.val < 100
  12. ),
  13. cte2 AS (
  14.   SELECT
  15.     2 AS val
  16.   UNION
  17.   ALL
  18.   SELECT
  19.     val + 1 AS val
  20.   FROM
  21.     cte2
  22.   WHERE
  23.     cte2.val < 100
  24. )
  25. SELECT
  26.   val AS prime
  27. FROM
  28.   cte1
  29. WHERE
  30.   NOT EXISTS (
  31.     SELECT
  32.       val
  33.     FROM
  34.       cte2
  35.     WHERE
  36.       val < cte1.val
  37.       AND cte1.val % val = 0
  38.   )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement