我想计算日期为空的行数。我尝试了以下
SELECT R.COUNTRY_CD,COUNT(R.EFFECTIVE_END_DT) AS d_null
FROM REIMBURSEMENT R
GROUP BY R.COUNTRY_CD,R.EFFECTIVE_END_DT
HAVING R.COUNTRY_CD = @COUNTRY_CD AND R.EFFECTIVE_END_DT IS NULL
但它给 d_null 为 0 ...
我如何比较日期NULL
我想计算日期为空的行数。我尝试了以下
SELECT R.COUNTRY_CD,COUNT(R.EFFECTIVE_END_DT) AS d_null
FROM REIMBURSEMENT R
GROUP BY R.COUNTRY_CD,R.EFFECTIVE_END_DT
HAVING R.COUNTRY_CD = @COUNTRY_CD AND R.EFFECTIVE_END_DT IS NULL
但它给 d_null 为 0 ...
我如何比较日期NULL
COUNT
只计算非NULL
条目。
尝试COUNT(*)
或COUNT(1)
代替COUNT(R.EFFECTIVE_END_DT)
.
由于您提供了Country_CD
as 参数,并且您只需要NULL
日期,因此您可以将查询简化为:
SELECT R.Country_CD, COUNT(*) AS d_null
FROM Reimbursement R
WHERE R.Country_CD = @Country_CD AND R.Effective_End_DT IS NULL
试试这个
SELECT R.COUNTRY_CD,COUNT(R.EFFECTIVE_END_DT) AS d_null
FROM REIMBURSEMENT R
GROUP BY R.COUNTRY_CD,R.EFFECTIVE_END_DT
HAVING R.COUNTRY_CD = @COUNTRY_CD AND DATE_FORMAT(R.EFFECTIVE_END_DT,"%y") IS NULL