MySQL Forums
Forum List  »  Newbie

Re: count occurrences by month
Posted by: Peter Brawley
Date: December 07, 2018 05:45PM

Assuming a table maint( loc id, dt datetime, ... ) andassumingt the requirement is for year-by-year monthly sums ...

select loc, left(dt,7) as yrmo, count(*) N
from maint
group by loc, yrmo
order by loc, yrmo;

If you don't need yearly data, change yrmo to month(dt) as mo, but you'll need to normalise results for the number of months represented in the table.

Options: ReplyQuote


Subject
Written By
Posted
December 07, 2018 04:57PM
Re: count occurrences by month
December 07, 2018 05:45PM
December 08, 2018 09:11AM
December 08, 2018 01:32PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.