[Sdruby] SQL refactoring question
Patrick Crowley
patrick at mokolabs.com
Fri Jan 19 18:54:15 GMT 2007
I've put together a Widget that monitors auction activity.
It hits my Rails app every 15 seconds, and returns the total amount
raised by the auction (top bid for each item x the number of items).
But I hate seeing this scroll by in my logs:
SELECT * FROM bids WHERE (item_id = 1 AND proxy != 1) ORDER BY amount
DESC, time DESC LIMIT 1
SELECT * FROM bids WHERE (item_id = 2 AND proxy != 1) ORDER BY amount
DESC, time DESC LIMIT 1
SELECT * FROM bids WHERE (item_id = 3 AND proxy != 1) ORDER BY amount
DESC, time DESC LIMIT 1
How would you guys refactor this? Can this be expressed as a single
query?
-- Patrick
More information about the Sdruby
mailing list