Created
November 19, 2015 02:57
-
-
Save cihangir/407509f0c5ef446fce42 to your computer and use it in GitHub Desktop.
SQL FizzBuzz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH RECURSIVE numbers(n) AS ( | |
SELECT 1 | |
UNION ALL | |
SELECT n + 1 | |
FROM numbers | |
WHERE n < 102 | |
) SELECT CASE | |
WHEN n % 3 = 0 AND n % 5 = 0 THEN | |
'FizzBuzz' | |
WHEN n % 3 = 0 THEN | |
'Fizz' | |
WHEN n % 5 = 0 THEN | |
'Buzz' | |
ELSE | |
to_char(n, '999') | |
END as result | |
FROM | |
numbers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment