2015-04-18 43 views
0
SELECT * 
FROM `placement_ans` A, `placement_quiz` B 
left join `placement_time` C on (A.state=C.state) 
where 
A.no_place=C.no_place and A.no_stu=C.no_stu and A.no_place=B.no_place and A.place_q=B.no_q and YEAR(A.place_date) = YEAR(curdate()) and MONTH(A.place_date) = MONTH(curdate()) and A.no_place=208 and A.no_stu=793 order by A.place_q ASC 

誤差 未知列「A.state」在「關於條款」左連接有一個「未知列」錯誤

我使用

SELECT * 
FROM `placement_ans` A, `placement_quiz` B 
left join `placement_time` C on (placement_ans.state=C.state) 
where 
A.no_place=C.no_place and A.no_stu=C.no_stu and A.no_place=B.no_place and A.place_q=B.no_q and YEAR(A.place_date) = YEAR(curdate()) and MONTH(A.place_date) = MONTH(curdate()) and A.no_place=208 and A.no_stu=793 order by A.place_q ASC 

也試過,但它不」不像是會要工作

我有一個像

placement_time 
state num 
100  10 

placement_ans 
state something 
100  11   
100  22   
55  33   
22  55   
33  77   

,我想打印出來的表格,多數民衆贊成

placement_ans 
state something num 
100  11   10 
100  22   10 
55  33   null 
22  55   null 
33  77   null 
+1

這意味着該表中沒有這樣的列。除非你添加它,否則你不能使它工作。 –

+0

表中有一列名爲「狀態」的列表placement_ans – user54987

+0

數據庫告訴你沒有。使用'SHOW CREATE TABLE placement_ans'再次檢查。不管你提出什麼查詢,如果數據庫說沒有這樣的列,那麼就沒有這樣的列。 –

回答

0

嘗試把你的左連接順序如下圖所示:

SELECT * 
FROM placement_ans A 
left join placement_time C on (A.state=C.state), 
placement_quiz B 
where 
A.no_place=C.no_place and A.no_stu=C.no_stu and A.no_place=B.no_place and A.place_q=B.no_q and YEAR(A.place_date) = YEAR(curdate()) and MONTH(A.place_date) = MONTH(curdate()) and A.no_place=208 and A.no_stu=793 order by A.place_q ASC 
+0

沒關係,它的工作原理 – user54987

+0

做一件事1首先刪除第三個表,即placement_quiz,並在您的查詢塊。檢查它是否正在工作逐漸添加ono-one條件進一步得到您的願望結果 –

+0

嘿,你刪除了你的評論,請回復我回去是否正在工作 –

1

從給出的示例數據集和預期的結果你不需要參考表placement_quiz,它可以做到

select a.*,b.num from placement_ans a 
left join placement_time b on b.state = a.state