Skip to content

Instantly share code, notes, and snippets.

@tensiondriven
Created July 3, 2012 17:28
Show Gist options
  • Save tensiondriven/3041218 to your computer and use it in GitHub Desktop.
Save tensiondriven/3041218 to your computer and use it in GitHub Desktop.
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