我的Mysql表看起来像这样
Field A Field B
Red yes
Blue yes
Red no
Green no
Blue yes
Blue yes
Green no
Green yes
Red no
我希望结果是:
Red 1
Blue 3
Green 1
任何帮助
答案 0 :(得分:0)
条件计数
SELECT FieldA, COUNT( CASE WHEN FieldB = 'Yes' THEN 1 END)
FROM YourTable
GROUP BY FieldA
答案 1 :(得分:0)
SELECT FieldA, count(FieldA)
FROM table
WHERE table.FieldB = "yes"
GROUP BY FieldA