我用标准 SQL 编写查询,并在 MySQL 中对其进行了测试。
现在,当我尝试在 PostgreSQL 中运行它们时,我得到了各种各样的错误,我不太明白。这是在 MySQL 中工作的原始查询:
CREATE VIEW popularCSsections AS (
SELECT sect.csid, COUNT(sc.sid) as numStudents
FROM courseSection sect, studentCourse sc, department d
WHERE sect.csid = sc.csid
AND sect.dcode = d.dcode
AND dname = "Computer Science"
GROUP BY sect.csid
HAVING numStudents > 2
);
给出这个错误:
psql:a2tables:60: ERROR: column "Computer Science" does not exist
LINE 8: AND department.dname = "Computer Science"
^
您能帮我理解错误的性质并帮助我修复它们吗?
附加问题:
CREATE VIEW popularCSsections AS (
SELECT sect.csid, COUNT(sc.sid) as numStudents
FROM courseSection sect, studentCourse sc, department d
WHERE sect.csid = sc.csid
AND sect.dcode = d.dcode
AND dname = 'Computer Science'
GROUP BY sect.csid
HAVING numStudents > 2
);
错误:
psql:a2tables:70: ERROR: column "numstudents" does not exist
LINE 8: HAVING numStudents > 2
^