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
答案 0 :(得分: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
答案 1 :(得分:0)
这应该这样做:
SELECT TOP 1 * FROM myTable ORDER BY major DESC, minor DESC, build DESC