0

我在 SQL 中使用如下透视查询:

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

结果我在空单元格中得到 0,是否可以在结果页面中显示空值而不是 0?

4

1 回答 1

0

最简单的解决方案是使用 NULLIF 快捷方式,如下所示:

SELECT  classification
, NULLIF([BSL],0) AS BSL
, NULLIF([AQ],0) AS AQ
, NULLIF([KYN],0) AS KYN
, NULLIF([BSL] + [AQ] + [KYN],0) AS CR_TTL 
       FROM  
      (  
       SELECT classification, Shed  
       FROM PunctualityMain WHERE Date >= '4/1/2012' AND Date <= '6/30/2012'    
      ) x 
      PIVOT  
     (  
      COUNT(Shed)  
      FOR Shed IN ([BSL],  [AQ],  [KYN]))  p  
于 2012-06-26T12:07:15.797 回答