解决不明确的SQL语法错误的正确方法是什么?

时间:2019-02-25 04:26:37

标签: mysql mysql-error-1064

我正在写一个查询,该查询将从以下关系中找到最大班级人数的学生姓名。我正在使用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')' 

2 个答案:

答案 0 :(得分:1)

您可以尝试这种方式。

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

答案 1 :(得分:1)

您可以在下面尝试-每种都不是有效的语法,这就是为什么会出现错误

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)