Skip to content

Instantly share code, notes, and snippets.

@yancya
Last active October 30, 2016 06:51
Show Gist options
  • Save yancya/22ab4ca61e75b6fa7b76be267db1658d to your computer and use it in GitHub Desktop.
Save yancya/22ab4ca61e75b6fa7b76be267db1658d to your computer and use it in GitHub Desktop.
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