select month,count(id) as 次数 from (select max(month) as month,id from 表 group by id ) a group by a.month
select month,id,count(*) from TABLE group by month ,id having month<>max(month) union select max(month),id,count(*) from TABLE group by id
select month,count(distinct id) from (select * from 表 aa where not exists(select 1 from 表 bb where aa.month<bb.month and aa.id=bb.id)) temp group by month
select month, count(id) AS 次数 from ( select max(month) AS month, id from table group by id ) A group by month
from (select max(month) as month,id from 表 group by id ) a
group by a.month
group by month ,id having month<>max(month) union select max(month),id,count(*) from TABLE
group by id
(select * from 表 aa where not exists(select 1 from 表 bb where aa.month<bb.month and aa.id=bb.id)) temp
group by month
select max(month) AS month, id from table group by id
) A group by month