2014-02-06 122 views
-3

我在我的mysql數據庫中有三個表。 jobrequest - jobno,vehicleno 勞動 - 日期,jobno4,AMOUNT2 materialcost日期,jobno2,AMOUNT3 當用戶從jobrequest表中選擇jobno,我想顯示總labourcost和materialcost ..... 的這裏是我的代碼左連接表的總和

$ result = mysql_query(「SELECT jobrequest.jobno,jobrequest.vehicleno,SUM(amount2)AS amount2,SUM(amount3)AS amount3,FROM jobrequest LEFT JOIN materialcost ON jobrequest.jobno = materialused.jobno2左加入勞動on jobrequest.jobno = labour.jobno4 WHERE(jobrequest.jobno ='$ item1')「);

回答

1
SELECT jobrequest.jobno, jobrequest.vehicleno, 
SUM(amount2) AS amount2, SUM(amount3) AS amount3 FROM jobrequest 
LEFT JOIN materialcost ON jobrequest.jobno = materialused.jobno2 
LEFT JOIN labour ON jobrequest.jobno = labour.jobno4 
WHERE (jobrequest.jobno = '$item1') 
group by jobrequest.jobno, jobrequest.vehicleno 
+0

它的工作,答案是AMOUNT2 = 32868.539&AMOUNT3 = 19876.不過,正確的答案是AMOUNT2 = 10956.18&AMOUNT3 = 4969. – user3089848

+0

具有u應用於日期字段一些過濾? –

+0

他的權利,如果想要一個日期特定的數據然後申請一個filer像:其中(jobrequest.jobno ='$ item1'和labour.date ='$ item2') – jainvikram444