实现功能:按t1分组,在每组中,把最大的t2所对应的一整条数据取出来。
1.表Table:
t1???????????? t2????????? t3
--------------------------
aaa??????????? 100????????? ==
bbb??????????? 80?????????? ==
aaa??????????? 90
ccc??????????? 70
ccc??????????? 500????????? ==
ccc??????????? 20
bbb??????????? 30
bbb??????????? 40
bbb??????????? 50
2.语句:
select A.* from Table A,(select t1,max(t2) as t2 from Table group by t1) B where A.t1=B.t1?? and A.t2=B.t2 order by A.t1 desc
3.结果:
t1???????????? t2????????? t3
--------------------------
ccc??????????? 500????????? ==
aaa??????????? 100????????? ==
bbb??????????? 80?????????? ==
?