开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜