今天群里有人问了个问题是这样的:
然后有群友是这样回答的
select name,sum(case when stype=4 then money*(-1) else money end ) as M
from table
group by name
我想了想,应该可以用IF函数
于是改了下
select name,sum(money*IF(stype=4,-1,1)) as M
from table
group by name
两种方式那种更效率还未测试。
今天群里有人问了个问题是这样的:
然后有群友是这样回答的
select name,sum(case when stype=4 then money*(-1) else money end ) as M
from table
group by name
于是改了下
select name,sum(money*IF(stype=4,-1,1)) as M
from table
group by name