Created
July 15, 2012 12:23
-
-
Save siosio/3116555 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
select case | |
when mod(seq.col1, 3) = 0 and mod(seq.col1, 5) = 0 then | |
'fizzbuzz' | |
when mod(seq.col1, 3) = 0 then | |
'fizz' | |
when mod(seq.col1, 5) = 0 then | |
'buzz' | |
else | |
to_char(seq.col1) | |
end fizzbuzz | |
from ( | |
select v1.col1 + (v2.col1 * 10) col1 | |
from ( | |
select 0 col1 from dual | |
union select 1 from dual | |
union select 2 from dual | |
union select 3 from dual | |
union select 4 from dual | |
union select 5 from dual | |
union select 6 from dual | |
union select 7 from dual | |
union select 8 from dual | |
union select 9 from dual | |
) v1, | |
( | |
select 0 col1 from dual | |
union select 1 from dual | |
union select 2 from dual | |
union select 3 from dual | |
union select 4 from dual | |
union select 5 from dual | |
union select 6 from dual | |
union select 7 from dual | |
union select 8 from dual | |
union select 9 from dual | |
) v2 | |
order by 1 | |
) seq | |
where seq.col1 <> 0 | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment