一、按日期分组查询
1.可以使用substring_index截取比如2021-03-01 00:00:00空格前的数据
select SUBSTRING_INDEX(warningdate," “,1) as ‘日期’,count(*) as ‘告警次数’ from alarmmessdata where warningdate between ‘2021-03-01 00:00:00’ and ‘2021-04-28 23:59:59’ group by SUBSTRING_INDEX(warningdate,” ",1);
2.可以使用cast把比如2021-03-01 00:00:00转化成date格式2021-03-01
select CAST(warningdate AS date) as ‘日期’,count(*) as ‘告警次数’ from alarmmessdata where warningdate between ‘2021-03-01 00:00:00’ and ‘2021-04-28 23:59:59’ group by CAST(warningdate AS date);