I have a MySQL query that's using SUM() to take the sum of a column, BUT what I need it to do is basically this:

If the string in another column is 'BUY', then I want to add the number in my column, but if this other column has 'SEL', I want to subtract the number in my column. I'm not sure how to go about this.

Any help ASAP would be appreciated. Thanks. :confused:

Use an IF clause, like in

select sum(amount * if(ordertype='BUY',1,-1)) from mytable

If this does not suit your needs, submit a test case.

I have a MySQL query that's using SUM() to take the sum of a column, BUT what I need it to do is basically this:

If the string in another column is 'BUY', then I want to add the number in my column, but if this other column has 'SEL', I want to subtract the number in my column. I'm not sure how to go about this.

Any help ASAP would be appreciated. Thanks. :confused:

Nevermind. What I needed was slightly different and was even a simpler fix.