mysql sum showing wrong answer for decimal type
sales_id = 12
product_rate = 2090.00 making_charge = 83.60 handling_charge = 0.00all of them are decimal(10,2) type. My query is
SELECT SUM( making_charge + product_rate + handling_charge ) AS tax_tourn
FROM `sales_details`
WHERE `sales_id` =12
the result i am getting is
tax_tourn = 10784.40 which is not right2090.00+83.60+0.00=2173.60
why is mysql showing wrong answer?
Details Newly Added
I have two tables sales and sales_details . sales_id is the primary key of sales and sales_details_id is the primary key for sales_details. sales_id is the foreign key in sales_开发者_高级运维details. There can multiple rows in sales_details with same sales_id.
But in our case (sales_id
=12) there is only one row.
It sounds like you have more than one row where sales_id =12
.
If this code returns more than 1 as the answer you have more than 1 row matching your where clause.
SELECT COUNT(*)
FROM `sales_details`
WHERE `sales_id` =12
精彩评论