表中字段:type,idnum,name,time均为char型
我想查找每一种类型中idnum最大的那条数据,比如type一共分为:red,blue,yellow
查找结果为
red, 该类型最大的idnum对应的idnum,name,time
blue, 该类型最大的idnum对应的idnum,name,time
yellow,该类型最大的idnum对应的idnum,name,time
select t.* from tb t where idnum = (select max(idnum) from tb where type = t.type) select t.* from tb t where not exists (select 1 from tb where type = t.type and idnum > t.idnum)