巢由

2016-09-22 15 views
1

當前查詢上沒有顯示這個查詢的一組現場參加:巢由

Select Name, Charge_code, Charge, Max(Mod)Mod, Max(date)Date 
From Table1 
Where Name is not Null and Name <>'' and Charge is not Null and charge_code is not null 
Group by Name, Charge_Code, Charge 

在這同一table1的我也有名爲「IDNUM」一個名稱標識號和一個單獨的表(表2 )我還在表2中的一個單獨的列中具有相同的標識符編號「IDNum」和位置標識。在表3中,我將該位置標識附加到實際位置名稱「location_Name」。這是我想加入我的數據集。

最後我想返回以下結果:

名稱|位置|收費代碼|收費| Mod |日期

如何將聯接嵌入到現有查詢中,以根據該標識符號碼撤回位置名稱,但不在結果中顯示標識號碼?對不起,如果這是一個簡單的問題,我是新的。 感謝

想這無濟於事:

​​
+1

提示:'JOIN'是做你想做的。 –

+0

這就是我試過的,它沒有去。 選擇姓名,費用代碼,費用,最大(Mod)Mod,最大值(日期)日期,地點 從表1 加入位置table1.IDNum = Table2 .IDNum 其中名稱不爲空且名稱<>''且費用不爲空且charge_code不爲空 按名稱,費用代碼,費用分組 – Slipand

+0

您忘記在'JOIN'後面加上'ON' – Mark

回答

1

如果你想加入2個表,那麼你需要用表2加入了兩遍連接表1和表3與表2.通過這種方式,你可以在表3

Select Name, Table3.Location_Name as Location, 
     Charge_code as 'Charge Code', Charge, 
     Max(Mod) as Mod, Max(date) as Date 
From Table1 
    Left Join Table2 on Table1.IDNum = Table2.IDNum 
    Left Join Table3 on Table2.LocationID = Table3.LocationID 
Where Name is not Null and Name <>'' and Charge is not Null and charge_code is not null 
Group by Name, Charge_Code, Charge 

獲取數據在here你可以瞭解更多關於JOIN。然後你可以決定哪個JOIN最適合你的情況