方法一(效率最高):
select * from test as a
where typeIndex = (select max(b.typeIndex) from test b where a.type = b.type );
方法二(效率次之):
select a.* from test a,
(select type,max(typeindex) typeindex from test group by type) b
where a.type=b.type and a.typeindex = b.typeindex order by a.type
方法三(效率最低):
select * from
(
select *,ROW_NUMBER() OVER(PARTITION BY type ORDER BY typeindex DESC) AS num
from test
)t where t.num=1
网友评论