Skip to content

Instantly share code, notes, and snippets.

@exul
Last active November 25, 2015 09:47
Show Gist options
  • Save exul/8b42cac2c32bf1c9667f to your computer and use it in GitHub Desktop.
Save exul/8b42cac2c32bf1c9667f to your computer and use it in GitHub Desktop.
SELECT fundables.id AS project_id,
DATE_PART('year', fundables.started_at) AS start_year,
DATE_PART('year', fundables.started_at + INTERVAL '1 day' * fundables.duration) AS end_year,
ARRAY_AGG(pledges.id) AS pledge_ids
FROM fundables
INNER JOIN pledges
ON pledges.project_id = fundables.id
WHERE type = 'Project'
AND fundables.successful = 'f'
AND DATE_PART('year', fundables.started_at) != DATE_PART('year', fundables.started_at + INTERVAL '1 day' * fundables.duration)
GROUP BY fundables.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment