Skip to content

Instantly share code, notes, and snippets.

@siosio
Created July 15, 2012 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siosio/3116555 to your computer and use it in GitHub Desktop.
Save siosio/3116555 to your computer and use it in GitHub Desktop.
SQLでfizzbuzz
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