## Project Euler 007 – TSQL

17 03 2011

Problem 7

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10001st prime number?

Solution

— By listing the first six prime numbers:

— 2, 3, 5, 7, 11, and 13, we can see that

— the 6th prime is 13.

— What is the 10001st prime number?

SELECT number FROM

(SELECT row_number() OVER (ORDER BY number) as primeindex, number

FROM Number

WHERE isprime = 1) Primes

WHERE Primes.primeindex = 10001

Discussion

On the surface this solution might seem pretty ‘meh’, but I’m a big fan.  It’s obviously going to be my fastest solution because it’s a simple look up – very common in real life scenarios.  I also got to use row_number() and a subquery as a data source which always delight me.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8878806,"math_prob":0.99320626,"size":857,"snap":"2019-43-2019-47","text_gpt3_token_len":253,"char_repetition_ratio":0.124267295,"word_repetition_ratio":0.16666667,"special_character_ratio":0.29638273,"punctuation_ratio":0.14973262,"nsfw_num_words":2,"has_unicode_error":false,"math_prob_llama3":0.9746582,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-11-15T10:02:23Z\",\"WARC-Record-ID\":\"<urn:uuid:32b95963-b708-412f-91de-e911438d9fda>\",\"Content-Length\":\"67070\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:a1503231-0ef0-4c1e-97f8-d9ddc0b4e981>\",\"WARC-Concurrent-To\":\"<urn:uuid:9e089804-abb8-4dae-bd7f-7ef1a4dda093>\",\"WARC-IP-Address\":\"192.0.78.24\",\"WARC-Target-URI\":\"https://azzlsoft.com/2011/03/17/project-euler-007-tsql/\",\"WARC-Payload-Digest\":\"sha1:PS3OCG7U72X3OZ6FD6CKPMJHRVW2NH4I\",\"WARC-Block-Digest\":\"sha1:UANAJFHM4VKVXGS6QBHQHODJAITYFV5J\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-47/CC-MAIN-2019-47_segments_1573496668618.8_warc_CC-MAIN-20191115093159-20191115121159-00352.warc.gz\"}"}