我正在写一个查询,该查询将从以下关系中找到最大班级人数的学生姓名。我正在使用MySQL服务器并正在使用MySQL Workbench。
Student(snum: integer, sname: string, major: string, level: string, age: integer)
Class(name: string, meets_at: time, room: string, fid: integer)
Enrolled(snum: integer, cname: string) Faculty(fid: integer, fnarne: string, deptid: integer)
这是我尝试实现查询的方式。
SELECT F.fname , COUNT(*) AS CourseCount
FROM faculty F, class C
WHERE F.fid = C.fid
GROUP BY F.fid , F.fname
HAVING EVERY (C.room = 'R128');
但是,我不断收到无法修复的错误。
Error Code: 1064. 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 '(C.room = 'R128')'
最佳答案
您可以在下面尝试-每个都不是有效的语法,这就是为什么您会出错
select * from
(
select F.fname, count(*) as CourseCount
from faculty as F
join class as C on C.fid = F.fid and C.room = 'R128'
group by F.fid, F.fname
)A where CourseCount in (select max(coursecount) from (select F.fname, count(*) as CourseCount
from faculty as F
join class as C on C.fid = F.fid and C.room = 'R128'
group by F.fid, F.fname)B)
关于mysql - 解决不明确的SQL语法错误的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54859487/