我试图创建一个新表,其中只有sname
的最大值等于num_courses
这是临时表n
中的一列。仅显示等于临时表中最大值的实例
SELECT s.sname, n.num_courses
FROM (SELECT e.sid, COUNT(distinct e.cno) as num_courses
FROM enroll e
GROUP BY e.sid) n, student s
WHERE s.sid = n.sid AND n.num_courses = (SELECT MAX(n.num_course) from n) x;
是否有可能只显示等于在临时表中找到的最大值的实例? (参见第二WHERE
条款的最后一行)
这是错误:
ERROR 1064 (42000) at line 1 in file: 'q7.sql': You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near 'x' at line 5
它说的错误是在第1行,但是当我删除最后一行的最后一句,有没有错误。
没有分组by子句。所以max将**从不**在这里返回多行。 – GurV
这似乎也不起作用。仍然给我一个错误。 –