on子句中的'id\u training'列不明确

brccelvz  于 2021-06-15  发布在  Mysql
关注(0)|答案(4)|浏览(330)

这个问题在这里已经有答案了

where子句中的mysql'user\u id'不明确问题(4个答案)
两年前关门了。
我想显示课程名称数据,但我得到:
on子句中的“id\u training”不明确。
查询中的错误在哪里?

CREATE TABLE `examination` (
`id_exam` int(32) NOT NULL,  
`class_name` varchar(100) NOT NULL,
`id_training` int(32) NOT NULL, 
`id_question` int(32) NOT NULL,
`total` int(3) NOT NULL,  
`exam_duration` int(5) NOT NULL,
`start` datetime NOT NULL,
`end` datetime NOT NULL,
`passing_grade` int(3) NOT NULL,
`id_user` int(32) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `training` (
`id_training` int(32) NOT NULL,  
`course_code` varchar(25) NOT NULL,
`course_title` varchar(100) NOT NULL,
`training_time` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

查询:

SELECT e.id_exam
     , e.class_name
     , e.id_training
     , e.total
     , e.exam_duration
     , e.start_exam
     , e.end_exam
     , e.passing_grade
     , t.course_title 
FROM examination e
INNER JOIN training t
ON id_training = course_tilte
eit6fx6z

eit6fx6z1#

SELECT e.id_exam, e.class_name, e.id_training, 
e.total, e.exam_duration, e.start_exam, 
e.end_exam, e.passing_grade, t.course_title 
FROM examination e
INNER JOIN training t  
ON e.id_training = t.course_title
oaxa6hgo

oaxa6hgo2#

出现此错误的原因“on子句中的列'id\u training'不明确”是两个表中都存在相同的列,因此由于在where子句中指定id\u training列的原因,sql与应使用的表混淆,因此始终使用别名指定。

SELECT e.id_exam
     , e.class_name
     , e.id_training
     , e.total
     , e.exam_duration
     , e.start_exam
     , e.end_exam
     , e.passing_grade
     , t.course_title 
  FROM examination e
  JOIN training t
    ON e.id_training = t.id_training
ma8fv8wu

ma8fv8wu3#

请试穿一下:

ON t.id_training = e.id_training
0qx6xfy6

0qx6xfy64#

您的查询看起来不正确。应该是这样的:

SELECT examination.id_exam, examination.class_name, examination.id_training, examination.total, examination.exam_duration, examination.start_exam, examination.end_exam, examination.passing_grade, training.course_title 
FROM examination 
INNER JOIN training 
ON training.id_training = examination.id_training

相关问题