Created
July 3, 2012 17:28
-
-
Save tensiondriven/3041218 to your computer and use it in GitHub Desktop.
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
last_week = <<EOT | |
-- chart_total_time_by_day | |
SELECT SUM ( EXTRACT( EPOCH FROM entries.end) - EXTRACT( EPOCH FROM entries.start) ) / 60 / 60 AS ct, | |
sub_dates.val AS d | |
FROM | |
(select '#{start_date.strftime('%Y-%m-%d')}'::date + generate_series(0, abs('#{start_date.strftime('%Y-%m-%d')}'::date - '#{end_date.strftime('%Y-%m-%d')}'::date)) AS val) AS sub_dates | |
LEFT OUTER JOIN | |
(select * FROM entries WHERE user_id = #{userid} #{where_task_id_clause}) AS entries | |
ON | |
date_trunc('day', entries.created_at) = sub_dates.val | |
GROUP BY | |
sub_dates.val | |
ORDER BY | |
sub_dates.val DESC | |
LIMIT 60 | |
EOT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment