Last active
May 26, 2020 09:29
-
-
Save niczky12/8e63fe8a6f0e23e4ba720f47c130a75d to your computer and use it in GitHub Desktop.
doing fizzbuzz with BigQuery case when statements
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 | |
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