1
0
mirror of https://github.com/osmarks/random-stuff synced 2024-11-08 05:29:54 +00:00
random-stuff/99-bottles.sql

5 lines
282 B
MySQL
Raw Normal View History

2021-01-29 16:34:10 +00:00
WITH RECURSIVE c(x)AS(VALUES(99)UNION ALL SELECT x-1 FROM c WHERE x>0),a(x, s)AS(SELECT x,SUBSTR(' bottles',1,(x<>1)+7)||' of beer'FROM c)SELECT PRINTF('%d%s on the wall
%d%s
Take one down, pass it around
%d%s on the wall',a.x,a.s,a.x,a.s,a.x-1,b.s)FROM a JOIN a AS b ON b.x=a.x-1;