标签: mysql sql
我怎样才能使此查询具有正确的语法? (MySQL的)
谢谢。
SELECT (count(a) WHERE a = 1)-(count(a) WHERE a = 0) FROM table
答案 0 :(得分:4)
试试这个。
SELECT SUM(CASE WHEN a=1 THEN 1 ELSE 0 END)- SUM(CASE WHEN a=0 THEN 1 ELSE 0 END) AS Result FROM table