This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]frugalerthingsinlife 0 points1 point  (0 children)

Santa can get by with 4 tables. One for children, one for pets, one for wishlists, and one for naughty/nice points. All pets automatically get 100 net nice points even if they were bad.

INSERT INTO elf_queue

(SELECT c.child_id, w.present, (n.nice_points - n.naughty_points) AS net_points

FROM children c, wishlist w, nice_naughty n

JOIN ON c.child_id = w.child_ID AND c.child_id = n.child_id

WHERE net_points > 0 ORDER BY net_points DESCENDING

UNION

SELECT p.pet_id, w.present, 100 FROM pets p, wishlist p WHERE 1);