sql某个字段类型获取分组后取某字段最大最新一条记录

获取分组后取某字段最大一条记录
方法一:(效率最高)
  1. select * from test as a
  2. where typeindex = (select max(b.typeindex)
  3. from test as b
  4. where a.type = b.type );

方法二:(效率次之)
  1. select
  2. a.* from test a,
  3. (select type,max(typeindex) typeindex from test group by type) b
  4. where a.type = b.type and a.typeindex = b.typeindex order by a.type
展开阅读全文

没有更多推荐了,返回首页