EnexoOnoma
EnexoOnoma

Reputation: 8836

Easy mySQL Group By question

If in a mysql table RESERVATIONS there are DATE_ARRIVAL, DATE_DEPARTED and TOTAL_EARN columns

How do I Group By month, all earnings in 2010?

Upvotes: 1

Views: 50

Answers (2)

Tom Mac
Tom Mac

Reputation: 9853

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?)

Upvotes: 1

Karolis
Karolis

Reputation: 9572

select year(DATE_ARRIVAL) year, month(DATE_ARRIVAL) month, sum(TOTAL_EARN)
from RESERVATIONS 
group by year, month
order by year, month

Upvotes: 0

Related Questions