1

我需要有人更正下面的陈述。先感谢您。

SELECT CATEGORY
--WHAT PERIOD?
,'P3' AS PERIOD
,'2013' AS FISCALYEAR        
,COUNT(CASE SecurityLayer WHEN 'dblayer' THEN SecurityLayer ELSE '' END) DB_SEC_COUNT         
,COUNT(CASE SecurityLayer WHEN 'Applayer' THEN SecurityLayer ELSE '' END) APP_SEC_COUNT  
FROM [db_eCAM].[dbo].[tbl_SecChecks]  
GROUP BY CATEGORY
4

2 回答 2

2

你是否试图返回这些东西匹配的次数?然后使用

SELECT CATEGORY
--WHAT PERIOD?
,'P3' AS PERIOD
,'2013' AS FISCALYEAR  
,SUM(CASE SecurityLayer WHEN 'dblayer' then 1 else 0 end) AS DB_SEC_COUNT
,SUM(CASE SecurityLayer WHEN 'Applayer' then 1 else 0 end) AS APP_SEC_COUNT
FROM [db_eCAM].[dbo].[tbl_SecChecks]  
GROUP BY CATEGORY

试试看。

于 2012-04-20T19:50:38.613 回答
2

不要计算列,而是尝试对其求和(否则,无论其值如何,每一行仍将被计算在内):

SELECT CATEGORY
--WHAT PERIOD?
,'P3' AS PERIOD
,'2013' AS FISCALYEAR        
,SUM(CASE SecurityLayer WHEN 'dblayer' THEN 1 ELSE 0 END) DB_SEC_COUNT         
,SUM(CASE SecurityLayer WHEN 'Applayer' THEN 1 ELSE 0 END) APP_SEC_COUNT  
FROM [db_eCAM].[dbo].[tbl_SecChecks]  
GROUP BY CATEGORY
于 2012-04-20T19:51:09.507 回答