Home > database >  Mysql query a month count data every day
Mysql query a month count data every day

Time:10-19

Every day I want to check a month amount of alarm GROUP, GROUP BY groups, query before some year every month when I use the count (case when * * * *), but also to write 12 count (case when * * * *), query and month when every day is too much trouble, in this way have what method can be convenient?

CodePudding user response:

Data every day in a row, with the case before the method;
If the daily data of each line, direct group, like this:
Select groups, date_format (col_date, '% d'), sum (if (col_alert, null, 0, 1))
The from tab_name
Where date_format (col_date, '% Y - % m)=' 2020-01 '
Group by groups, date_format (col_date, '% d');

CodePudding user response:

reference 1st floor lhdz_bj response:
data every day in a row, with the case before the method;
If the daily data of each line, direct group, like this:
Select groups, date_format (col_date, '% d'), sum (if (col_alert, null, 0, 1))
The from tab_name
Where date_format (col_date, '% Y - % m)=' 2020-01 '
Group by groups, date_format (col_date, '% d');


1, 2, 3,,,,,,
A group of 12, 234, 234
Group B, 123, 234
23, 234, 234 group C
And 23, 234 2


I want to do is the output of the scheduling, so do after export to excel charts is more convenient
  • Related