Wednesday, March 9, 2016

We're moving!

Hey readers! Thanks so much for dropping by. As of March 2016, the blog has MOVED to my personal site. Please visit http://www.elainekellner.com/sql for more bad jokes and great BI tips.

Wednesday, January 6, 2016

A More Efficient 12 Days of Christmas

In a fit of nerdiness, I decided to re-write the classic Christmas carol "The Twelve Days of Christmas" in SQL:
SELECT (ROW_NUMBER() OVER (ORDER BY Xmas1.DayNum DESC)) * Xmas2.DayNum AS GiftQuantity,
Xmas2.DayNum,
Xmas2.GiftTitle
FROM TwelveDaysXmas Xmas1
INNER JOIN TwelveDaysXmas Xmas2
ON Xmas1.DayNum = Xmas2.DayNum

Results:
GiftQuantity DayNum   GiftTitle
12           12       Drummers Drumming
22           11       Pipers Piping
30           10       Lords a-leaping
36           9        Ladies Dancing
40           8        Maids a-milking
42           7        Swans a-swimming
42           6        Geese a-laying
40           5        Gold Rings
36           4        Calling Birds
30           3        French Hens
22           2        Turtle Doves
12           1        Partridge In Pear Tree
See? Much easier than singing 12 choruses!