如何将以下3个查询压缩为一个?
select count(*) as fs1 from feedback WHERE feedbackStatus = 1
select count(*) as fs2 from feedback WHERE feedbackStatus = 2
select count(*) as fs3 from feedback WHERE feedbackStatus = 3
答案 0 :(得分:4)
select count(*) as count_status, feedbackStatus
from feedback
where feedbackStatus in (1, 2, 3)
group by feedbackStatus
答案 1 :(得分:2)
您可以尝试这样的查询:
select
sum(feedbackStatus = 1) as fs1,
sum(feedbackStatus = 2) as fs2,
sum(feedbackStatus = 3) as fs3
from feedback;