Skip to content

Instantly share code, notes, and snippets.

@hidayat365
Created March 15, 2012 06:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hidayat365/2042442 to your computer and use it in GitHub Desktop.
Save hidayat365/2042442 to your computer and use it in GitHub Desktop.
Fizz Buzz Solution using MySQL
select
-- logic untuk fizzbuzz
case
when baris %15 = 0 then 'FizzBuzz'
when baris %3 = 0 then 'Fizz'
when baris %5 = 0 then 'Buzz'
else baris end fizzbuzz
from (
-- generate 100 baris row dan beri nomor
select @no := @no+1 baris
from (select @no := 0) t0
, (select 1 union all select 2 union all select 3 union all select 4) t1
, (select 1 union all select 2 union all select 3 union all select 4) t2
, (select 1 union all select 2 union all select 3 union all select 4) t3
, (select 1 union all select 2 union all select 3 union all select 4) t4
limit 100
) tx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment