Computers are just the thing for automating repetitive tasks.
WITH RECURSIVE b(beer) AS (
VALUES (99)
UNION ALL
SELECT
beer-1
FROM b
WHERE beer > 0
)
SELECT
format(
E'%s of beer on the wall, %s of beer.\n%s %s of beer on the wall.\n',
CASE beer
WHEN 0 THEN 'No more bottles'
ELSE beer || ' bottle' || CASE beer WHEN 1 THEN '' ELSE 's' END
END,
CASE beer
WHEN 0 THEN 'no more bottles'
ELSE beer || ' bottle' || CASE beer WHEN 1 THEN '' ELSE 's' END
END,
CASE beer
WHEN 0 THEN 'Go to the store and buy some more. '
ELSE 'Take one down and pass it around,'
END,
CASE beer
WHEN 2 THEN 'one bottle'
WHEN 1 THEN 'no more bottles'
WHEN 0 THEN '99 bottles'
ELSE format('%s bottles', lead(beer) OVER (ORDER BY beer DESC))
END
)
FROM b;