Easy mySQL Group By question
If in a mysql tabl开发者_如何转开发e RESERVATIONS there are DATE_ARRIVAL, DATE_DEPARTED and TOTAL_EARN columns
How do I Group By
month, all earnings in 2010
?
select monthname(DATE_ARRIVAL),sum(TOTAL_EARN) from RESERVATIONS where DATE_ARRIVAL between '2010-01-01' and '2010-12-31 23:59:59' group by monthname(DATE_ARRIVAL);
Though it kind of depends on which column you want to base your predicate (DATE_ARRIVAL or DATE_DEPARTED?)
select year(DATE_ARRIVAL) year, month(DATE_ARRIVAL) month, sum(TOTAL_EARN)
from RESERVATIONS
group by year, month
order by year, month
精彩评论