Created
July 16, 2010 17:57
-
-
Save zacclark/478680 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
select | |
count(case when photos.created_at < trips.start_date then distinct(photos.id) end) as before, | |
count(case when photos.created_at >= trips.start_date and photos.created_at < trips.end_date then distinct(photos.id) end) as during, | |
count(case when photos.created_at >= trips.end_date then distinct(photos.id) end) as after | |
from trips | |
inner join trip_segments | |
on trip_segments.trip_id = trips.id | |
inner join trip_segment_photos | |
on trip_segment_photos.trip_segment_id = trip_segments.id | |
inner join photos | |
on photos.id = trip_segment_photos.photo_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment