0

我得到了这个结果,给出的答案是bluefeet

Equipt  BSL    AQ
TFP     3      2
TM      1      0
VCB     18     6
VCD     5      8

查询脚本是

 SELECT  Equipt, [BSL] AS BSL, [AQ] AS AQ 
 FROM 
 ( 
 SELECT Equipt, Shed 
 FROM PunctualityMain WHERE Date >= '4/1/2012' AND Date <= '4/30/2012' AND classification    = 'Loco' 
) x
PIVOT 
( 
COUNT(Shed) 
FOR Shed IN ([BSL], [AQ])
)  p 

是否可以在上述脚本中添加一个总字段,例如访问交叉表

Equipt  BSL    AQ     TTL
TFP     3      2     5
TM      1      0     1
VCB     18     6     24
VCD     5      8     13
4

1 回答 1

0

您应该能够通过包含一个新列来添加总计字段:

SELECT  Equipt, [BSL] AS BSL, [AQ] AS AQ, ([BSL] + [AQ]) as TTL
FROM 
( 
     SELECT Equipt, Shed 
     FROM PunctualityMain 
     WHERE Date >= '4/1/2012' AND Date <= '4/30/2012' 
          AND classification    = 'Loco' 
) x
PIVOT 
( 
    COUNT(Shed) 
    FOR Shed IN ([BSL], [AQ])
)  p 
于 2012-06-20T15:47:07.013 回答