Skip to content

Instantly share code, notes, and snippets.

@niczky12
Last active May 26, 2020 09:29
Show Gist options
  • Save niczky12/8e63fe8a6f0e23e4ba720f47c130a75d to your computer and use it in GitHub Desktop.
Save niczky12/8e63fe8a6f0e23e4ba720f47c130a75d to your computer and use it in GitHub Desktop.
doing fizzbuzz with BigQuery case when statements
WITH
numbers AS (
-- this is the same as before, but wrapped in a with statement
SELECT
*
FROM
UNNEST(GENERATE_ARRAY(1, 100)) AS num )
SELECT
num,
CASE
WHEN MOD(num, 15) = 0 THEN 'FizzBuzz'
WHEN MOD(num, 5) = 0 THEN 'Buzz'
WHEN MOD(num, 3) = 0 THEN 'Fizz'
ELSE
CAST(num AS string)
END
AS result
FROM
numbers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment