Return a count of bookings for each month
Question
Return a count of bookings for each month, sorted by monthExpected Results
| month | count |
|---|---|
| Sun Jul 01 2012 00:00:00 GMT+0000 (Coordinated Universal Time) | 658 |
| Wed Aug 01 2012 00:00:00 GMT+0000 (Coordinated Universal Time) | 1472 |
| Sat Sep 01 2012 00:00:00 GMT+0000 (Coordinated Universal Time) | 1913 |
| Tue Jan 01 2013 00:00:00 GMT+0000 (Coordinated Universal Time) | 1 |
Your Answer
Your Results
Loading database...
Answers and Discussion
select date_trunc('month', starttime) as month, count(*)
from cd.bookings
group by month
order by month This one is a fairly simple reuse of concepts we've seen before. We simply count the number of bookings, and aggregate by the booking's start time, truncated to the month.