我正在研究SQL Server 2008 R2.我想要得到这笔钱.
这是我的查询
select
SUM(
case
when sec.SecurityTypeID = 2 then SUM(quantity)*(sec.AnnualIncomeRate/100)
when sec.SecurityTypeID = 5 then 0
when sec.SecurityTypeID = 11 then SUM(quantity)*sec.AnnualIncomeRate
else SUM(quantity)*sec.AnnualIncomeRate
end
) AS ProjectedIncome
from Transactions as t
Run Code Online (Sandbox Code Playgroud)
当我执行它时,请给我以下错误.
消息130,级别15,状态1,行3
无法对包含聚合或子查询的表达式执行聚合函数.
我知道我正在使用带有case子句的sum函数.但我需要找到这个案例陈述的总和.