MYSQL 依据字段值分段统计

SELECT sum(mun),max from (

select (ceil(distance/500)-1)*500 as min,

ceil(distance/500)*500 as max,

count(*) mun

from tablename where date_format(alarm_date, '%Y-%m-%d') =date_format('2023-02-03', '%Y-%m-%d') group by ceil(distance/20)

) t GROUP BY max

;

你可能感兴趣的:(数据库,sql,数据库)