Question

Return a count of bookings for each month, sorted by month
Schema reminder
DB schema

Expected Results

month count
2012-07-01 00:00:00 658
2012-08-01 00:00:00 1472
2012-09-01 00:00:00 1913
2013-01-01 00:00:00 1

Your Answer Hint Help Save Run Query


              

Answers and Discussion Show

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.

You're probably going to want the date_trunc function again.

Keyboard shortcuts:


Other hints: