mardi 30 juin 2015

SQLite Sum & Group BY Statement

productName | purchasePrice | tax | price 
------------+---------------+-----+--------

Product 1   | 5099          | 16  | 10099
Product 1   | 5099          | 16  | 10099
Product 1   | 5099          | 16  | 10099
Product 1   | 5099          | 16  | 10099
Product 2   | 5099          | 19  | 10099
Product 2   | 5099          | 19  | 10099
Product 2   | 5099          | 19  | 10099

My Calculation for the Total Profit is this

SUM( price- ( price * tax/100.0  + purchasePrice)) as Profit

Result as Profit = 22780.210000000006

My Calculation for the Profit of every Product is this

SUM(price- (price*TAX/100.0 + purchasePrice)) as Profit GROUP BY productName

Result as Profit for Product 1 = 13536,6

Result as Profit for Product 2 = 9243,57

Total 22780,17 Whats wrong here and how can i get the same value?

Aucun commentaire:

Enregistrer un commentaire