2017-05-28 75 views
0

我得到的錯誤ERROR 1066(42000):不是唯一的表/別名: 'STUDENT_TBL'不是唯一的表/別名(42000)

select STUDENT,DATE,MARK from Assessments inner join STUDENT_TBL onAssessments,ID_STUDENT=STUDENT_TBL,STD_ID inner joinVisit_log,ID_STUDENT=STUDENT_TBL,STD_ID where STUDENT_TBL,STD_IDIN (select ID_STUDENT FROM Assessments group by ID_STUDENT having avg(MARK)>3.7);

如何解決呢?

回答

0

您應該使用的'.'代替','訪問Table_Name.column_name

select STUDENT,DATE,MARK 
from Assessments AS Assessments 
inner join STUDENT_TBL AS STUDENT_TBL on Assessments.ID_STUDENT=STUDENT_TBL.STD_ID 
inner join Visit_log AS Visit_log on Visit_log.ID_STUDENT=STUDENT_TBL.STD_ID 
where STUDENT_TBL.STD_ID IN (select ID_STUDENT FROM Assessments 
          group by ID_STUDENT having avg(MARK)>3.7 

還可以使用別名等Assessments.ID_STUDENT而在選擇子句選擇列,如果這些存在於一個以上的表

+0

現在我有類似的錯誤:ERROR 1052(23000):字段列表中的'DATE'列不明確 –

+0

@ArtemMatrosov從哪個表引用'DATE'? – Rohan

+0

從「評估」表 –

0

如果您使用的模式和表名,你必須用單獨的點像這樣

select STUDENT, Assessments .`DATE`,MARK from Assessments 
inner join STUDENT_TBL on Assessments.ID_STUDENT=STUDENT_TBL.STD_ID 
inner join Visit_log.ID_STUDENT=STUDENT_TBL.STD_ID 
where STUDENT_TBL.STD_ID IN (select ID_STUDENT FROM Assessments group by ID_STUDENT having avg(MARK)>3.7); 
+0

現在我有一個錯誤,如:在字段列表列「DATE」:ERROR 1052(23000)是不明確的 –

+0

我在我的回答中加入了 –

相關問題