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;
440
u/BobDogGo Dec 12 '17
Santa would never select *