0

桌子:

purchase_stock_entry(id,purchase_party_id,bill_no,dt,product_id,qty,price,type)
purchase_party_name(purchase_party_id,name_shop)

我希望列中的输出(bill_no,name_shop,sum(qty*price))与这两个表的连接一样

我也在尝试:

select p1.bill_no,p2.name_shop,p1.qty*p1.price as [Total],p1.dt from purchase_stock_entry
p1,purchase_party_name p2 where p1.purchase_party_id=p2.id

但总和我怎么能?

4

2 回答 2

2
SELECT bill_no, name_shop, SUM(qty * price) AS [total]
FROM purchase_stock_entry INNER JOIN purchase_party_name
  ON purchase_stock_entry.purchase_party_id = purchase_party_name.purchase_party_id
GROUP BY bill_no, name_shop;
于 2013-10-18T12:41:37.567 回答
0

请使用这个,它可以工作

SELECT p1.billno, p2.name_shop, sum(p1.price * p1.qty) FROM purchase_stock_entry p1, purchase_party_name p2 WHERE p1.purchase_party_id = p2.purchase_party_id

于 2013-10-18T13:05:15.983 回答