SELECT * FROM (SELECT ROW_NUMBER() OVER(PARTITION BY 分组的字段 ORDER BY 需要排序的字段 ASC ) lev,t.* from 表名 t) WHERE lev = 1ORDER BY 需要排序的字段 ASC
select a.* from 表名 a where exists(select id from (select max(id) as id from 表名 WHERE userid='110' group by 分组字段) b where a.id=b.id)
select * from 表名 a where exists(select id from 表名 b where id in(select max(id) as id from 表名 WHERE userid='110' group by 分组字段) and a.id=b.id) order by 分组字段