Ken
Ken

Reputation: 3

MySQL query that multiplies 2 fields then adds all results

I need a MySQL query that will Select records between a date range, multiply the 'Qty' column and the 'unit price' column for each result, and then add all of those results together. I'll need help with the correct syntax as well.

Something like this:

SELECT 'Qty','unit value' 
  FROM `Inventory` (Qty * unit value for each result) then (add all results together) 
 WHERE `Date Received` BETWEEN '2012-1-1' AND '2013-1-1'

Any help appreciated!

Upvotes: 0

Views: 39

Answers (1)

peterm
peterm

Reputation: 92795

Are you looking for something like this?

SELECT SUM(Qty * UnitValue) total
  FROM Inventory 
 WHERE DateReceived BETWEEN '2012-01-01' AND '2013-01-01'

Here is SQLFiddle demo

Upvotes: 1

Related Questions