请问这个SQL为什么会错?
select sum(sal) from bonus
select sum(sal) from bonus where sal>0,
这两句合起来,
如果不用子查询怎么写呢?
不应该是
select sum(sal) as 剩余积分, sum(case when sal> then 1 else 0 end) as 正总积分 from bonus;
这样么,
可是正总积分查出来的数据却不是select sal from bonus where sal>0
------解决方案--------------------sum(case when sal>0 then sal else 0 end)
这样试试
------解决方案--------------------select sum(sal) as 剩余积分, sum(case when sal>0 then sal else 0 end) as 正总积分 from bonus;