「MySQL入門」count(distinct case xxxで重複要素を排除してカウントする
例1
SELECT COUNT(DISTINCT CASE
WHEN addId >= 202 AND addId <= 258
THEN addId2 END)
FROM t_addressTbl
例2
SELECT SUM(CASE
WHEN addId >= 202 AND addId <= 258
THEN 1 ELSE 0 END)
FROM t_addressTbl
例3
SELECT column1,column2,column3,sum(column4)
FROM TEST_TBL
GROUP BY column1,column2,column3