选择具有max属性值的行

时间:2014-06-04 07:03:51

标签: sql sql-server tsql

我有下表 enter image description here

我想提出下表enter image description here

我想要的是选择每个客户端具有最大版本的行。 Tahnks提前。

2 个答案:

答案 0 :(得分:3)

试试这个

SELECT * From Table1 T
         JOIN (SELECT clientid,Max(version) As MVer 
               From Table1 Group By clientid) S
         ON T.clientid = S.clientid And T.version  = S.MVer

<强> Fiddle Demo

答案 1 :(得分:0)

select * from 
(
select *,rn=Dense_rank()over(partition by Clientid order by version desc) from table
)x
where x.rn=1

FIDDLE DEMO

相关问题