Skip to content

Instantly share code, notes, and snippets.

@rubysolo
Created June 26, 2013 16:47
Show Gist options
  • Save rubysolo/5869134 to your computer and use it in GitHub Desktop.
Save rubysolo/5869134 to your computer and use it in GitHub Desktop.
cfd query
SELECT d.day, s.description, SUM(1) AS count
FROM (SELECT current_date - days.day AS day FROM generate_series(0,
(SELECT CAST(EXTRACT(epoch FROM NOW() - DATE(MIN(start_date))) / 86400 AS integer) FROM pivotal_tracker_story_histories)
,1) AS days(day)) d INNER JOIN pivotal_tracker_story_histories h ON d.day BETWEEN h.start_date AND COALESCE(h.end_date, current_date)
INNER JOIN pivotal_tracker_story_statuses s ON s.id = h.status_id
GROUP BY d.day, s.description
ORDER BY d.day, s.description
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment