You're not getting paid enough when

Filed under: sql zombies 

You awaken at 3:50am from a dream where a town of zombies is chasing you, trying to vomit some sort of zombie blood goo on you so that you'll become a zombie too and instead of having a glass of warm milk, hugging your pillow and sobbing, or any other sort of normal activity, you comfort yourself by writing this query:

UPDATE dips
SET revenue = rst.revenue
FROM (
  SELECT d.id, dip_count * r.rate AS revenue
  FROM
    (SELECT d1.*, rate_code
     FROM dips d1 LEFT JOIN accounts
     ON (d1.accounts_id = accounts.id)) AS d
  LEFT JOIN
    rates AS r
  ON (d.carriers_id = r.carriers_id)
  WHERE d.rate_code = r.rate_code
    AND d.revenue IS NULL
    AND d.carriers_id IS NOT NULL
) AS rst
WHERE dips.id = rst.id;

I may indeed be eaten by zombies someday, but thank God I'll never again use MySQL.



0 comments Leave a comment