0

我收到错误 ERROR 1066 (42000): Not unique table/alias: '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);

如何解决?

4

2 回答 2

1

您应该使用'.'而不是','访问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如果这些列存在于多个表中,则在选择子句中选择列时也使用类似别名

于 2017-05-28T12:33:22.010 回答
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);
于 2017-05-28T12:33:00.233 回答