We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Print Prime Numbers
Print Prime Numbers
Sort by
recency
|
1356 Discussions
|
Please Login in order to post a comment
i've not yet learnt cte can someone help with a basic sql code. i wrote this but it incorrect
SELECT GROUP_CONCAT(num SEPARATOR '&') AS primes FROM ( SELECT n.num FROM numbers n WHERE n.num <= 100 AND n.num > 1 AND NOT EXISTS ( SELECT 1 FROM numbers d WHERE d.num > 1 AND d.num < n.num AND n.num % d.num = 0 ) ) AS prime_list;
MYSQL
WITH RECURSIVE numbers AS ( SELECT 2 AS num UNION ALL SELECT num + 1 FROM numbers WHERE num + 1 <= 1000 ), primes AS ( SELECT num FROM numbers n WHERE NOT EXISTS ( SELECT 1 FROM numbers d WHERE d.num < n.num AND d.num > 1 AND n.num % d.num = 0 ) ) SELECT GROUP_CONCAT(num ORDER BY num SEPARATOR '&') AS prime_list FROM primes;
For MySQL