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.
theideabulbAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
KeldenConnect With a Mentor Commented:
Try:

select sum( case when new then newprice else priceused end ) as totalValue, category
from products
group by category
0
 
theideabulbAuthor Commented:
good job, you got to it quick!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.