Created
March 19, 2014 12:21
-
-
Save Coaden/9640538 to your computer and use it in GitHub Desktop.
Simpler gouping by date,and easier for changing to hours and later adding the join to the classification DB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sql = "SELECT t.date, COUNT(se.id) FROM (" \ | |
" SELECT to_char(date_trunc('day', (%s::TIMESTAMP - offs )), 'YYYY-MM-DD')" \ | |
" AS date" \ | |
" FROM GENERATE_SERIES(0, %s, 1)" \ | |
" AS offs" \ | |
") t " \ | |
"LEFT OUTER JOIN (" \ | |
" SELECT id, created_at::TIMESTAMP FROM text_textdb" \ | |
" WHERE stream_id=%s" \ | |
") se " \ | |
"ON (t.date=to_char(date_trunc('day', se.created_at), 'YYYY-MM-DD')) " \ | |
"GROUP BY t.date " \ | |
"ORDER BY t.date" | |
sql = "SELECT t.date, COUNT(se.id) FROM (" \ | |
" SELECT to_char(date_trunc('hour', (%s::TIMESTAMP - '1 HOUR'::INTERVAL * offs )), 'YYYY-MM-DD HH24')" \ | |
" AS date" \ | |
" FROM GENERATE_SERIES(0, %s, 1)" \ | |
" AS offs" \ | |
") t " \ | |
"LEFT OUTER JOIN (" \ | |
" SELECT id, created_at::TIMESTAMP FROM text_textdb" \ | |
" WHERE stream_id=%s" \ | |
") se " \ | |
"ON (t.date=to_char(date_trunc('hour', se.created_at::TIMESTAMP), 'YYYY-MM-DD HH24')) " \ | |
"GROUP BY t.date " \ | |
"ORDER BY t.date" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment