我收到错误ERROR 1066(42000):不是唯一的表/别名:'STUDENT_TBL'

select STUDENT,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);

如何解决?

最佳答案

您应使用'.'而不是','来访问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之类的别名

关于mysql - 非唯一表/别名(42000),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44227273/

10-11 02:59