This query only tests odd numbers as even numbers won't be prime anyway. SELECT (ROW_NUMBER() OVER (ORDER BY (SELECT 1)) * 2) + 1 AS Of course, if you do need to calculate the prime numbers between 1 and 100, the following is fairly efficient: WITH base AS At this small of a scale, why waste CPU each time to calculate a bunch of values that have been known for a very long time, and take up hardly any memory to store? SELECT tmp.įROM (VALUES (2), (3), (5), (7), (11), (13), By far the quickest and easiest way to print "all the prime numbers (1-100)" is to fully embrace the fact that prime numbers are a known, finite, and unchanging set of values ("known" and "finite" within a particular range, of course).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |