开发者

Easy mySQL Group By question

开发者 https://www.devze.com 2023-04-08 12:01 出处:网络
If in a mysql tabl开发者_如何转开发e RESERVATIONS there are DATE_ARRIVAL, DATE_DEPARTED and TOTAL_EARN columns

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

精彩评论

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