一、方法一:(效率最高)
select * from test a
where a.num = (select max(b.num) from tes b where a.id = b.id );
二、方法二:(效率次之)
select a.* from test a,
(select id,max(a.num) typeindex from test group by id) b
where a.id = b.id and a.num = b.num order by a.id
三、方法三:
select a.* from test a
inner join (select id , max(num) num from test group by id) b
on a.id = b.id and a.num = b.num order by a.id
四、方法四:(效率最低)
select * from
(
select *,ROW_NUMBER() OVER(PARTITION BY id ORDER BY num DESC) as num from test
) t
where t.num = 1