Created
March 15, 2012 06:21
-
-
Save hidayat365/2042442 to your computer and use it in GitHub Desktop.
Fizz Buzz Solution using MySQL
This file contains hidden or 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 | |
-- 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