select month,count(id) from(select max(month) as month,id from yourtable group by id ) a group by a.month

解决方案 »

  1.   

    select month,count(id) as 次数 
    from (select max(month) as month,id from 表 group by id ) a 
    group by a.month
      

  2.   

    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
      

  3.   

    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
      

  4.   

    select month, count(id) AS 次数 from (
    select max(month) AS month, id from table group by id
    ) A group by month