这是我的两张表:
CREATE TABLE Classes (
Class_ID Varchar2(2) CONSTRAINT Classes_Class_ID_Pk PRIMARY KEY,
Class_Name VARCHAR(15) CONSTRAINT Classes_Class_Name_NN NOT NULL,
Price Number(5, 2),
Start_Date DATE,
End_Date DATE,
Start_Time Varchar2(5),
End_Time Varchar2(5),
Day VARCHAR(10),
Trainer_ID CONSTRAINT Classes_Trainer_ID_FK REFERENCES Trainers(Trainer_ID)
);
CREATE TABLE ClassSchedule (
Class_ID Varchar2(2) CONSTRAINT Classes_Class_ID_FK REFERENCES Classes(Class_ID),
Member_ID Varchar2(2) CONSTRAINT Members_Member_ID_FK REFERENCES Members(Member_ID),
Paid CHAR(1),
CONSTRAINT ClassSchedule_Combo_PK PRIMARY KEY (Class_ID, Member_ID)
);
现在,对于每个班级,我想列出班级 ID、班级名称、每个班级的价格、每个班级的成员数量以及每个班级的总收入。我只想显示那些超过 400 美元的组,并按计算出的总数对它们进行排序。这是我的查询不起作用:
SELECT
C.Class_Id,
Class_Name,
Price,
Count(S.Member_Id) AS Student_Count,
(Student_Count * Price) AS Class_Revenue
FROM Classes C,
ClassSchedule S
WHERE C.Class_ID = S.Class_Id
AND (Student_Count * Price) > 400
ORDER BY Class_Revenue DESC
任何帮助,将不胜感激。一直把我的头撞在墙上试图让它工作。