I have the following Input table:
Article Store Supplier NetPrice Pieces Sum Inventory Price Cond
NL1234 N001 3100000 161,5 2 323 7 123,45 2,47
NL1234 N001 3100000 161,5 0 0 4 103,8 2,08
NL1234 N001 3100000 161,5 0 0 23 120,8 1,21
I need to calculate the weighted average of the price for the number of inventory value. For example, Inventory*price for all selected rows divided by the total no. of inventory number.Mathematically,
((7*123.45)+(4*103.8)+(120.8))/(34)
SELECT
Article,
Store,
Supplier,
NetPrice,
sum(Pieces) as "Pieces",
sum(Sum) as "Sum",
sum(Inventory) as "Inventory",
(Inventory*Price)/sum(Inventory) as "Price",
(Inventory*Cond)/sum(Inventory) as "Cond"
FROM
table_name
WHERE
"Article" = 'NL1234'
GROUP BY
STORE,
SUPPLIER,
NetPrice,
Article
How can I extend/modify my select statement to get the following output:
Article Store Supplier NetPrice Pieces Sum Inventory Price Cond
NL1234 N001 3100000 161,5 2 323 34 119,35 1,57