Skip to content

Instantly share code, notes, and snippets.

@fodra
Created March 5, 2018 06:33
Show Gist options
  • Save fodra/7edb29f28b63c797c79d43391cb47714 to your computer and use it in GitHub Desktop.
Save fodra/7edb29f28b63c797c79d43391cb47714 to your computer and use it in GitHub Desktop.
-- get the 10 most recent sold listings for the specific agency
SELECT id, status, sold_price, sold_date
FROM listings_listing
WHERE agency_id = '3ab9adc2-7fd2-4b24-8cd0-d0cc69270fbf' AND status = 'S'
ORDER BY sold_date DESC LIMIT 10;
-- modify the query set to a new date somewhere between now and four weeks ago
UPDATE listings_listing
SET sold_date = now(),
source_type = 'M'
FROM ( SELECT id, status, sold_price, sold_date
FROM listings_listing
WHERE agency_id = '3ab9adc2-7fd2-4b24-8cd0-d0cc69270fbf' AND status = 'S'
ORDER BY sold_date DESC LIMIT 10) as subquery
WHERE listings_listing.id = subquery.id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment