给定sql:有没有方法引入结果集的总数?
SELECT
SUM(CASE
WHEN status = 3 THEN 1
ELSE 0
END) AS Open,
SUM(CASE
WHEN status = 4 THEN 1
ELSE 0
END) AS Close
FROM
Table1
WHERE
id = 2;
结果:
Open,Close
5,5
期望结果:
Open,Close,Total
5,5,10
3条答案
按热度按时间ymdaylpp1#
使用子查询
wfypjpf42#
再加一句话
2ic8powd3#
您可以使用cte:
http://www.mysqltutorial.org/mysql-cte/