表A
device
file
version数据a a.txt 1
a a1.txt 2
a a3.txt 3
a a4.txt 4
a a5.txt 5
b b1.txt 2
b b3.txt 3
b b4.txt 4
b b5.txt 5
c rc1.txt 2
c ce3.txt 3
c cza4.txt 4
c c25.txt 5想要获得每个device版本最高的那个文件

a a5.txt
b b5.txt
c c25.txt

解决方案 »

  1.   

    select t.* from a t where version = (select max(version) from a where device = t.device)select t.* from a t where not exists (select 1 from a where device = t.device and version > t.version)
      

  2.   

    select * from A t where not exists (select 1 from A where device = t.device and version>t.version)