我必须计算每个官员的情况,其中Survey =' abc'和活动=' FI'和(结果=' C' OR结果=' D')
这是我的完整SQL
SELECT officer, NULL,
SUM(IIF(ISNUMERIC(mkt) = TRUE AND Survey='dasda' AND Activity='FI' AND Outcome = 'C', Totalmin, 0 ) / 60),
SUM(Non), SUM(ICC), NULL, NULL, NULL, COUNT(IIF(Survey='abc' AND Activity='FI' AND (Outcome='C'or Outcome='D'), Totalmin, 0))
FROM [DB$]
GROUP BY officer " '
问题部分是
Count(IIF( Survey='abc' and Activity='FI' and (Outcome='C'or Outcome='D'), Totalmin, 0 ))
然而,我生成的结果并没有起作用。计数结果远不止答案。
答案 0 :(得分:1)
COUNT()
计算非NULL
值的数量。由于0
不为空,因此会计算。这有两个选择:
COUNT(IIF(Survey='abc' AND Activity='FI' AND Outcome IN ('C', 'D'), Totalmin, NULL))
或
SUM(IIF(Survey='abc' AND Activity='FI' AND Outcome IN ('C', 'D') AND Totalmin IS NOT NULL, 1, 0))