theideabulb
asked on
Help with SUM and IF with MySQL
I am trying to query the sum of products by category. I have prices for New and Used. I am trying to just show a report of overall sales by category. The new price and used prices are in two different columns.
Here is a general idea of what i am trying to do. This is Mysql 5. My example below is just me talking it out in a general matter to get the idea across.
select sum(if condition is new price new, else priceUsed) as totalValue
from products
group by category
I am not sure how to do the sum with the if statement, if that is even possible.
Here is a general idea of what i am trying to do. This is Mysql 5. My example below is just me talking it out in a general matter to get the idea across.
select sum(if condition is new price new, else priceUsed) as totalValue
from products
group by category
I am not sure how to do the sum with the if statement, if that is even possible.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER