如果可以在sql中创建变量并为其分配值,我感到困惑。 这是我已经尝试过的代码。
select facultyName, count(programcode) as 'Highest Value'
from program, faculty
where program.FacultyCode = faculty.FacultyCode
group by facultyname
having count(programcode) > 5;
这是我的讲师代码
SELECT t.FacultyName, t.ProgramCount
FROM (
SELECT Faculty.FacultyName, COUNT(*) AS 'Program Count'
FROM Program, Faculty
WHERE Program.FacultyCode=Faculty.FacultyCode
GROUP BY Faculty.FacultyCode) t GROUP BY t.FacultyName
HAVING MAX (t.ProgramCount) = (SELECT (MAX(p.ProgramCount
FROM (
SELECT Faculty.FacultyName, COUNT(*) AS 'Program Count'
FROM Faculty, Program
WHERE Faculty.FacultyCode = Program.FacultyCode
GROUP BY Faculty.FacultyName) )))p;
输出应为5。