2013-10-18 71 views
0

表:SQL查詢來訪問數據庫中執行

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 

但總和如何我可以?

+2

我想要一輛保時捷......你的問題是什麼? –

+0

我想輸出bill_no,name_shop,總和(數量*價格)這一列,但由bill_no獨特 –

+0

一些基本的格式將有所幫助。看看我的答案[這](http://stackoverflow.com/questions/19447784/splitting-and-exporting-multiple-tables-from-ms-access/19449390#19449390)作爲指導的問題。 –

回答

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; 
+0

謝謝[克里斯萊斯頓](http://stackoverflow.com/users/2778930/chris -rolliston) –

0

請使用,它可以工作

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

+0

沒有它的不工作。 –