我需要为特定条件计算count
并执行:
select count(Status) as Status from processing_unit_info where Status = 'Not Registered'
是否可以在单个查询中计算表中所有条目的count(*)
?
答案 0 :(得分:3)
是的,你可以。一种可能的解决方案:
SELECT
count(*) AS total,
SUM(Status = 'Not Registered') as Status
FROM
processing_unit_info
答案 1 :(得分:1)
是的,就像这样:
select count(Status),
sum(Status = 'Not Registered') as Status
from processing_unit_info
SUM()
函数中的布尔表达式的计算结果为true或false,即1或0.