0

我想用 2 个 COUNT() 列对 SQL Compact 4.0 DB 表进行查询。当特定列的十进制值大于或等于 3.0 时,第一列应计算所有行( COUNT(*) ),第二列应仅计算行

我做到了这一点:

SELECT COUNT(a.number) AS Participant, COUNT(b.specificColumn) AS Approved
FROM person AS a 
LEFT OUTER JOIN test AS b 
ON b.number = a.number

这样第二个 COUNT() 显然只会计算行,实际上有一个值!= NULL

4

2 回答 2

2

我不认为你可以使用计数来做到这一点。尝试使用 case 语句。未测试:

SELECT COUNT(a.number) AS Participant, 
SUM(case when b.specificColumn >3 then 1 else 0 end) as Approved
FROM person AS a 
LEFT OUTER JOIN test AS b 
ON b.number = a.number
于 2013-07-09T20:02:20.757 回答
0
SELECT COUNT(a.number) AS Participant,
       SUM(CASE WHEN b.specificColumn IS NULL THEN 0
                WHEN b.specificColumn >= 3 THEN 1
                ELSE 0) AS Approved
FROM person AS a 
LEFT OUTER JOIN test AS b 
ON b.number = a.number
于 2013-07-09T20:02:22.067 回答