只想计算已设置的行并避免未设置的行
SELECT COUNT(DISTINCT member_id) AS total_memebers,
COUNT(case member_feesdue when null then 1 else 0 end) AS total_feesdue
FROM sdg_members
答案 0 :(得分:2)
COUNT永远不会计算NULL。 SELECT COUNT(col)FROM tbl就足够了。
答案 1 :(得分:0)
我认为你试图将total_feesdue
计算在等于1的位置?
SELECT COUNT(DISTINCT member_id) AS total_memebers,
(SELECT COUNT(*) FROM sdg_members WHERE sdg_members = 1) AS total_feesdue
FROM sdg_members