C S*_*per 0 sql sql-server-2005
我有桌子:
Bonus Value
500 1400
1500 177
1800 453
1200 100
800 2500
200 50
780 740
Run Code Online (Sandbox Code Playgroud)
我想打印列的总和,以最大值为准.
我试过以下:
select
case when sum(bonus)>sum(Value) then sum(bonus) end
case when sum(Value)>sum(bonus) then sum(Value) end
from emp
Run Code Online (Sandbox Code Playgroud)
但我没有得到结果.
错误:
Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'case'.
Run Code Online (Sandbox Code Playgroud)
您的语法不正确,CASE关键字只出现一次:
select
case when sum(bonus)>sum(Value) then sum(bonus)
else sum(Value)
end as MaxSum
from emp
Run Code Online (Sandbox Code Playgroud)