SQL で FizzBuzz

 
PostgreSQL で FizzBuzz.

面接の際にどうぞ。(謎

with recursive fizzbuzz(i, result) as (
  select
  1, '1'
  union all
  select
  i + 1
  ,case when (i + 1) % 15 = 0 then 'FizzBuzz'
        when (i + 1) % 5 = 0 then 'Buzz'
        when (i + 1) % 3=  0 then 'Buzz'
        else (i + 1)::text end
  from fizzbuzz
  where i < 100
)
select * from fizzbuzz;

 
おまけ)
BigQuery用に loop で書き直そうと思ったけどメンドクサイからやめたw
手軽にやるならこれか。

select
i,
case when mod(i, 15) = 0 then 'FizzBuzz'
     when mod(i, 5) = 0 then 'Buzz'
     when mod(i, 3) = 0 then 'Fizz'
     else cast(i as string) end as result
from unnest(generate_array(1, 100)) as i;