Last active
December 30, 2021 09:52
-
-
Save Eunoia1729/7a1cc45d917b663cdd7793066cd5a4d7 to your computer and use it in GitHub Desktop.
Generate prime numbers in SQL till 1000
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH | |
RECURSIVE numbers(N) AS ( | |
SELECT 2 | |
UNION ALL | |
SELECT N + 1 FROM numbers | |
WHERE N < 1000 | |
) | |
SELECT F1.N | |
FROM numbers F1 | |
JOIN numbers F2 ON (F1.N % F2.N) = 0 | |
GROUP BY F1.N | |
HAVING COUNT(F2.N) = 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment