我有一个SQL语句,它根据值选择一组数据。
Select case when Count(score) >= 2 then 2 else Count(score) end as Count
from table
where questions = answered and score= 3
group by Surveyid
这打印出以下内容(这是正确的)
我最终需要将所有这些值加在一起。我已经想出了这个,但是我遇到了错误,似乎无法解决问题。
Select Sum(*)
From ( Select case when Count(score) >= 2 then 2 else Count(score) end as Count
from table
where questions = answered and score= 3
group by Surveyid ) C
答案 0 :(得分:0)
可能因为Sum(*),请尝试
Select Sum(C.Count)
答案 1 :(得分:0)
这解决了这个问题。
Select Sum(Count)
From ( Select case when Count(score) >= 2 then 2 else Count(score) end as Count
from table
where questions = answered and score= 3
group by Surveyid ) C