Project Euler 001 – TSQL

4 02 2011

Problem 1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

Solution

— I have a table called Number

— that has about 3 million

— integers starting at 1

— this problem is pretty

— simple from a query perspective

 

SELECT SUM(number) FROM Number

WHERE number < 1000

AND ((number % 3 = 0) OR (number % 5 = 0))

Discussion

When it’s possible to fill a table in a reasonable amount of time using brute force techniques, I will.  If the technique for filling the table is interesting I will demonstrate that.  I realize that in many cases this won’t be possible so I will have to use whatever “trick” is required to solve the problem before the sun burns out.

If you have questions, leave a comment or find me on Twitter (@azzlsoft) or email (rich@azzlsoft.com).

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: