Euler Project, Question 1

From PostgreSQL wiki

Revision as of 15:06, 19 May 2012 by Boshomi (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Snippets

Editing Euler Project

Works with PostgreSQL

8.4

Written in

SQL

Depends on

Nothing

One way to achieve the solution to question 1.

WITH RECURSIVE t1(a, b) AS (
        VALUES(0,0)
    UNION ALL
        SELECT CASE CAST(b AS BOOLEAN)
                      WHEN b % 3 = 0 THEN b
                      WHEN b % 5 = 0 THEN b
                END,
                b + 1
          FROM t1
         WHERE b < 1000
)
SELECT sum(a) FROM t1
Personal tools