group by
分组max(time)
inner join...on
sum(case when jfjs between 0 and 1000 then 1 else 0 end) as
0-1000``, -- 表名 table_p
-- id 身份证信息
-- time 时间
-- jfjs 需要汇总的字段
select
sum(case when jfjs between 0 and 1000 then 1 else 0 end) as `0-1000`,
sum(case when jfjs between 1000 and 2000 then 1 else 0 end) as `1000-2000`
--多条case判断区间
from table_p
INNER JOIN
(
select id as b_id ,max(time) as b_time
from table_p
group by gmsfzhm
) b
on id= b_id and time= b_time
mysql | 查询一个人最新的记录 并对某一字段进行汇总统计
原文:https://www.cnblogs.com/zhy-god/p/14818035.html