The IF function of SUM field in MYSQL use of conditional statistics (case)

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Today, someone asked a question is this group:

Then a group Friends replied

select name,sum(case when stype=4 then money*(-1) else money end ) as M
from table
group by name

I wanted to think, should be able to use the IF function

So the next change

select name,sum(money*IF(stype=4,-1,1)) as M
from table
group by name

Two ways that more efficiency not test.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Gavin at December 05, 2013 - 7:28 PM