Doing sum's if certain conditions are true

Posted by Gugu on Stack Overflow See other posts from Stack Overflow or by Gugu
Published on 2010-06-11T15:55:58Z Indexed on 2010/06/11 16:02 UTC
Read the original article Hit count: 120

Filed under:

I am trying to build a query that does a sum if a certain parameter is set. For example:

SELECT SUM(IF(<condition>,field,field)) AS total_value

...which is working correctly.

But i have more than one condition in IF(), like:

SELECT SUM(IF(<condition> <condition>,field,field)) AS total_value

..which is not working, could you have any idea what should be the right query for this.

© Stack Overflow or respective owner

Related posts about mysql