需要拉动每台计算机按特定任务序列执行的最后一步
编写一个SQL查询,以查询特定任务序列的计算机状态以及在任务序列运行期间执行的所有步骤。但是它显示了机器执行的所有步骤,而我的实际要求是为每台机器获得最后一步。
Netbios_Name0 Step ActionName Last Status
Computer1 0 xyx Failed
Computer1 1 xyz Success
Computer1 2 yyy Inprogres
Computer2 0 xzz Waiting
Computer2 1 xxy Failed
Computer3 0 xyz Failed
Computer3 1 xxx Accepted
Computer3 2 xzy Failed
Computer3 3 xzz Success
Select Netbios_name0
,Step
,ActionName
,Laststatus
from [v_R_System] System
join [vSMS_TaskSequenceExecutionStatus] TaskSequence
On TaskSequence.ResourceID = System.ResourceID
where packageID like '%PackageID%'
预期结果就像
Netbios_Name0 Step ActionName Last Status
Computer1 2 yyy Inprogres
Computer2 1 xxy Failed
Computer3 3 xzz Success
答案 0 :(得分:0)
如果您有可用的窗口功能...
select Netbios_Name0,Step,ActionName,Last Status
from
(
select t1.*, row_number() over (partition by Netbios_name0 order by Step desc) as rn
from MyTable t1
) x2
where x2.rn = 1