LoginSignup
0
1

SQLでのFizzBuzz

Posted at

さっき、記事にまとめたSQLの書き方で
私なりのfizzbuzzを作るとこんな感じになります。

with seq as (select generate_series(1,100) as seq)
, fizzbuzz as (select * 
                 from ( values (3,'fizz') 
                              ,(5,'buzz' ) 
                              , (15,'fizzbuzz')) as t (num , text))

select seq.seq
        , coalesce((select text     
                                from fizzbuzz 
                              where seq % num = 0 
                              order by num DESC
                              limit 1)
          ,seq ::text) as fizzbuzz
from seq

image.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1