0

我正在尝试从下表中创建一个视图,其中给出了 classId、学期、教授它的教授姓名以及该学期提供的部分数量。我尝试使用 SQL 查询创建视图:

CREATE SQL SECURITY INVOKER VIEW ClassesView AS SELECT Qualified.ClassId, Teaches.Semester, CONCAT(Professor.FName, Professor.LName) AS Name, Teaches.Section FROM Teaches, Professor, Qualified WHERE Qualified.EmpId = Professor.EmpId, Qualified.ClassId = Teaches.Class;

但这没有用。我将如何从下表中创建所需的视图?

CREATE TABLE Class
(
    ClassId VARCHAR(6),
    Description VARCHAR(30),
    NumCredits Integer,
    Prereq VARCHAR(20),
    PRIMARY KEY(ClassId)
);

CREATE TABLE Section
(
    ClassId VARCHAR(6),
    SecNo CHAR(10),
    Semester CHAR(4),
    ClassRoom VARCHAR(6),
    TimeOffered VARCHAR(18),
    PRIMARY KEY(SecNo),
    FOREIGN KEY(ClassId) REFERENCES Class(ClassId)  
);

CREATE TABLE Professor
(
    EmpId INTEGER,
    FName VARCHAR(10),
    LName VARCHAR(10),
    Dept VARCHAR(2),
    QualClass VARCHAR(40),
    PRIMARY KEY (EmpId)
);

CREATE TABLE Teaches
(
    Class VARCHAR(5),
    Section INTEGER,
    Semester CHAR(4),
    EmpId INTEGER,
    FOREIGN KEY (EmpId) REFERENCES Professor(EmpId)
);

CREATE TABLE Qualified
(
    EmpId INTEGER,
    ClassId VARCHAR(5)
);

谢谢你。任何帮助将不胜感激,因为它将帮助我学习 MySQL。

4

1 回答 1

0

存在语法错误(用 AND 替换逗号)

CREATE SQL SECURITY INVOKER VIEW ClassesView AS 
SELECT Qualified.ClassId, Teaches.Semester, CONCAT(Professor.FName, Professor.LName) AS Name, Teaches.Section 
FROM Teaches, Professor, Qualified 
WHERE Qualified.EmpId = Professor.EmpId AND Qualified.ClassId = Teaches.Class;
于 2014-07-25T16:12:40.553 回答