簡體   English   中英

在 mysql/php 問題中加入 3 個表

[英]Join 3 tables in mysql/php issue

我需要加入 3 個表並顯示所有數據:

以下查詢工作正常。 在這里,我加入了 2 個名為“comparitive_statement1”和“comparitive_st_sup”的表。 在這里,一切都很好。

SELECT tc.*,sum(tci.total_inr) as tot1, tci.supplier_name,tci.currency as currency2 FROM comparitive_statement1 tc INNER JOIN comparitive_st_sup tci ON tc.tender_id=tci.tender_id WHERE tc.tender_id='$tender_id' and tc.sup_name=tci.supplier_name GROUP BY tc.sup_name ORDER BY tc.sup_name ASC

現在我需要加入另一個名為“comparitive_st_tech_compliance”的表,其具有相同的招標 ID 和供應商名稱。 在這里,當我加入時,我的總數是錯誤的。 放置我已經完成的查詢:

SELECT tc.*, sum(tci.total_inr) as tot1, tci.supplier_name,tci.currency as currency2 FROM comparitive_statement1 tc INNER JOIN comparitive_st_sup tci ON tc.tender_id=tci.tender_id INNER JOIN comparitive_st_tech_compliance cl ON tci.tender_id=cl.tender_id and tc.sup_name=cl.supplier_name WHERE tc.tender_id='$tender_id'  GROUP BY tc.sup_name,cl.supplier_name ORDER BY tc.sup_name ASC

我做錯了什么?

可能是and tc.sup_name=cl.supplier_name部分

嘗試

   INNER JOIN comparitive_st_tech_compliance cl ON 
   tci.tender_id=cl.tender_id and tc1.supplier_name=cl.supplier_name 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM