Skip to content

Instantly share code, notes, and snippets.

@lizconlan
Created November 4, 2015 13:13
Show Gist options
  • Save lizconlan/c46378c6452edc1827d4 to your computer and use it in GitHub Desktop.
Save lizconlan/c46378c6452edc1827d4 to your computer and use it in GitHub Desktop.
WITH last_response_times AS (
SELECT events.info_request_id, MAX(events.created_at) AS last_response_time
FROM info_request_events events
JOIN incoming_messages
ON incoming_messages.id = events.incoming_message_id
WHERE
events.event_type = 'response' AND
incoming_messages.prominence = 'normal'
GROUP BY events.info_request_id
)
SELECT info_requests.id, last_response_times.last_response_time
FROM info_requests, last_response_times
WHERE
last_response_times.info_request_id = info_requests.id AND
awaiting_description = 't' AND
url_title != 'holding_pen' AND
user_id IS NOT NULL AND
prominence = 'normal' AND
last_response_time < '2015-09-21 11:45:48.319245'
ORDER BY last_response_time
LIMIT 20;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment