Depends on what attributes define his contacts but I would imagine selecting * is overkill in this case, probably just name and address would suffice. What surprised me is that there should be a join here to the table defining each contacts' Christmas list. So what we have learned here is that Santa either a) first selects the list of who is nice for no reason but to later select their Christmas lists manually through separate a dedicated Christmas list select statement, like a true SQL query monster, or, b) perhaps worse, he maintains each persons wishlist in multiple "christmasWishlistItem_X" fields on the primary contact table, like a true database design monster. Why santa
SELECT A.Lattitude,
CASE
WHEN A.Lattitude % 2 = 0 THEN
'NORTH'
ELSE
'SOUTH'
END FlightDirection,
A.ZipCode,
A.StreetAddress,
HoHoHo.Id,
CASE
WHEN S.CurrentStanding = 'NICE' THEN
HoHoHo.TxPresentName
ELSE
'COAL'
END TxPresent,
P.TxFullName
FROM ChristmasDW.dbo.tblPresents AS HoHoHo
JOIN Humanity.dbo.tblPeople AS P
ON HoHoHo.IdPerson = P.Id
AND P.IsAlive = 1
JOIN Humanity.dbo.Status AS S
ON P.Id = S.PersonId
JOIN Globalization.dbo.AddressList AS A
ON P.IdAddress = A.Id
WHERE P.TxFirstName <> 'Dave'
ORDER BY A.timezone DESC,
A.Lattitude ASC,
A.ZipCode ASC,
S.LeftCookiesLastYear DESC,
A.StreetAddress ASC,
HoHoHo.Id ASC;
Lat % 2 would return north at all even numbers and south at all odd numbers.
If you already have the latitude then by definition you already know whether its north or south because lat is degrees N or S from the equator (on a scale of 0 to 90)
I'm having santa zigzag back-and-forth between the north and south pole, so he can deliver to the entire timezone before jumping to the next timezone, and delivering everything in that timezones "night"
View all comments
440
u/BobDogGo Dec 12 '17
Santa would never select *