修复不明确的 SQL 语法错误的正确方法是什么?
What is the correct way to fix an ambiguous SQL syntax error?
我正在编写一个查询,该查询将从以下关系中查找注册人数最多 类 的学生姓名。我正在使用 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 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
您可以尝试以下 - 每个都不是有效语法,这就是您出错的原因
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 服务器并使用 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 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
您可以尝试以下 - 每个都不是有效语法,这就是您出错的原因
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)