Wednesday, 18 September 2013

Get aggregation values for all possible distinct entries in group by

Get aggregation values for all possible distinct entries in group by

Ok, I know the title is confusing, but the idea is pretty simple. I just
need to figure out how many flights were flown at five different sites
during a given time period. Sometimes a site won't have any flights during
the period and this is where I'm having the problem. If I use:
select count(*)
from Flight
where date between '9/9/2013' and '9/15/2013'
group by Site
order by Site
I will only get the sites that have actually flown, but I would like to
have those sites where there were no flights during during that period
(but have flown at other times and have records in the table) still return
a value of 0.

No comments:

Post a Comment