-3
Type  major  minor  build  module
----  -----  -----  -----  -----
290   0      0      1      Name1
290   1      0      1      Name1
290   1      0      2      Name1
300   0      0      1      Name2
300   2      0      1      Name2
300   2      1      1      Name2

我一直在尝试获取一个查询,以根据三列(major.minor.build)仅显示具有最高版本的行,每种类型。模块名称将替换模块类型。

根据样本数据,结果应为:

Type    major    minor    build    module
----    -----    -----    -----    ------
290     1        0        2        Name1
300     2        1        1        Name2
4

2 回答 2

4

要获得每种类型的最高值,您可以查询例如:

;with cte as (
    select Type, major, minor, build, module
        rn = row_number() over (partition by Type 
          order by major desc, minor desc, build desc)
    from TableName
)
select Type, major, minor, build, module
from cte
where rn=1
于 2013-08-03T14:37:02.730 回答
0

这应该这样做:

SELECT TOP 1 * FROM myTable ORDER BY major DESC, minor DESC, build DESC
于 2013-08-03T13:50:42.737 回答