2

各製品の価格を明確に定義しているいくつかの製品を含む見積もり文書を格納するmysqlデータベースと、契約の詳細、およびそれが属する顧客コードと見積もりコードを格納する契約のテーブルがあります。請求書に記載する見積もりの​​合計金額を確認するには、次のクエリがあります。

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

以下はsqproductsテーブルです(引用で指定された製品の詳細)

しかし、私は正しくないこの結果を取得します(1500米ドルになる必要があります)

4

1 に答える 1

0

そのブラインドヒット、これを試してください:

select
   sum(sqproducts.price * sqproducts.quantity) as 'total-price',
   squotations.currency as 'currency'
from
  sqproducts 
inner join squotations on (squotations.code=sqproducts.quotation_code)
inner join ccontracts on (sqproducts.quotation_code=ccontracts.squotation_code)

where 
  sqproducts.contracted=1
  AND sqproducts.quotation_code='QUOT/2012/1'
group by
  squotations.currency
于 2012-07-01T15:13:49.737 に答える