在 SQL Server 2008 R2 中的枢轴 table 中分组

Group by in pivot table in SQL Server 2008 R2

我如何按这个枢轴分组 table

select * 
from 
    (SELECT     
        ProductionID,ProductionDetailID,                
        [DeviceID],[DeviceSpeed],[LattNO] 
     from 
        (SELECT      
            * 
         from view_3 
         where ProductionID = 6) x pivot 
        (
            max(Value)FOR PropertyName  in ([DeviceID],[DeviceSpeed],[LattNO])
        )  AS pvt ) as  pp 

结果:

ProductionID  ProductionDetailID  DeviceID  DeviceSpeed  LattNO
6                     2             5           NULL      NULL
6                     2             NULL          8       NULL
6                     2             NULL         NULL      6
6                     3             1            NULL     NULL
6                     3             NULL          2       NULL

我怎样才能得到这个结果:

  ProductionID  ProductionDetailID  DeviceID  DeviceSpeed  LattNO
      6            2                  5          8          6
      6            3                  1          2          NULL

SELECT
ProductionID,ProductionDetailID, Sum(Cast(isnull([DeviceID],0​​) as Int)) [DeviceID],Sum(Cast(isnull([DeviceSpeed],0) as Int)) [DeviceSpeed],Case Sum(Cast(isnull ([LattNO],0) as Int)) When 0 then Null else Sum(Cast(isnull([LattNO],0) as Int)) End [LattNO] from ( SELECT * 来自 dbo.View_3
) x轴 ( max(Value)FOR PropertyName in ([DeviceID],[DeviceSpeed],[LattNO]) ) 作为列兵 按 ProductionID 分组,ProductionDetailID