sql query returns incorrect result

Posted by reza saberi on Stack Overflow See other posts from Stack Overflow or by reza saberi
Published on 2012-07-01T14:54:49Z Indexed on 2012/07/01 15:16 UTC
Read the original article Hit count: 195

Filed under:

I have a mysql database that stores quotation documents with some products that are clearly defining the price of each product in them, and a table for contracts storing contract details as well as customer code and quotation code to which it belongs. I have the following query to see how much is the total price of the quotation to write it in the invoice:

select
   sum(sqproducts.price * sqproducts.quantity) as 'total-price',
   squotations.currency as 'currency'
from
  sqproducts,
  ccontracts,
  squotations
where 
  sqproducts.contracted=1
  AND squotations.code=sqproducts.quotation_code
  AND sqproducts.quotation_code=ccontracts.squotation_code
  AND sqproducts.quotation_code='QUOT/2012/1'
group by
  currency

the following is the sqproducts table(details about the products named in quotation)

But I get this result which is not correct (it must result 1500 USD)

© Stack Overflow or respective owner

Related posts about mysql