[MySQL] 同じカラム合計値を複数条件で別々に
1 min read
SELECT SUM(CASE WHEN Jouhou = 'A' THEN 1 ELSE 0 END)as 'A',
SUM(CASE WHEN Jouhou = 'B' THEN 1 ELSE 0 END)as 'B',
SUM(CASE WHEN Jouhou IS NULL THEN 1 ELSE 0 END)as 'null'
FROM DBTable
SELECT SUM(CASE WHEN Jouhou = 'A' THEN 1 ELSE 0 END)as 'A',
SUM(CASE WHEN Jouhou = 'B' THEN 1 ELSE 0 END)as 'B',
SUM(CASE WHEN Jouhou IS NULL THEN 1 ELSE 0 END)as 'null'
FROM DBTable