HackerRank MySQL - Print Prime Numbers




Write a query to print all prime numbers less than or equal to 1000. Print your result on a single line, and use the ampersand (&) character as your separator (instead of a space).



  1. SELECT GROUP_CONCAT(NUMB SEPARATOR '&')
  2. FROM (
  3. SELECT @num:=@num+1 as NUMB FROM
  4. information_schema.tables t1,
  5. information_schema.tables t2,
  6. (SELECT @num:=1) tmp
  7. ) tempNum
  8. WHERE NUMB<=1000 AND NOT EXISTS(
  9. SELECT * FROM (
  10. SELECT @nu:=@nu+1 as NUMA FROM
  11. information_schema.tables t1,
  12. information_schema.tables t2,
  13. (SELECT @nu:=1) tmp1
  14. LIMIT 1000
  15. ) tatata
  16. WHERE FLOOR(NUMB/NUMA)=(NUMB/NUMA) AND NUMA<NUMB AND NUMA>1
  17. )
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube