Last active
October 30, 2016 06:51
-
-
Save yancya/22ab4ca61e75b6fa7b76be267db1658d to your computer and use it in GitHub Desktop.
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 rules(_n, msg) AS ( | |
VALUES (3, 'Fizz') | |
, (5, 'Buzz')) | |
, nums AS (SELECT generate_series(1, 100) AS n) | |
SELECT COALESCE(STRING_AGG(msg, '' ORDER BY _n), n::TEXT) | |
FROM nums | |
LEFT OUTER JOIN rules ON n % _n = 0 | |
GROUP BY n | |
ORDER BY n; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment