【发布时间】:2021-12-24 15:15:59
【问题描述】:
我的问题:
在#4 中,我无法连接两个视图,因为另一个视图具有聚合函数。与 #5
相同问题:
-
创建一个名为 studentDetails 的视图,该视图应显示学生姓名、入学日期、每单位总价以及就读科学或历史学科的学生的学科描述。
-
创建一个视图,将其命名为 BiggestPrice,它将显示主题 ID 和所有主题的最高单价总价。该视图应仅显示大于 1000 的最高单价总价。
--4.) Create a view name it as studentDetails, that would should show the student name,
-- enrollment date the total price per unit and subject description of students who are
-- enrolled on the subject Science or History.
CREATE VIEW StudentDetails AS
SELECT StudName, EnrollmentDate
--5.) Create a view, name it as BiggestPrice, that will show the subject id and highest total
-- price per unit of all the subjects. The view should show only the highest total price per unit
-- that are greater than 1000.
CREATE VIEW BiggestPrice AS
SELECT SubjId, SUM(Max(Priceperunit)) FROM Student, Subject
GROUP BY Priceperunit
这是我的桌子:
CREATE TABLE Student(
StudentId char(5) not null,
StudName varchar2(50) not null,
Age NUMBER(3,0),
CONSTRAINT Student_StudentId PRIMARY KEY (StudentId)
);
CREATE table Enrollment(
EnrollmentId varchar2(10) not null,
EnrollmentDate date not null,
StudentId char(5) not null,
SubjId Number(5) not null,
constraint Enrollment_EnrollmentId primary key (EnrollmentId),
constraint Enrollment_StudentId_FK foreign key (StudentId) references Student(StudentId),
constraint Enrollment_SubjId_Fk foreign key (SubjId) references Subject(SubjId)
);
Create table Subject(
SubjId number(5,0) not null,
SubjDescription varchar2(200) not null,
Units number(3,0) not null,
Priceperunit number(9,0) not null,
Constraint Subject_SubjId_PK primary key (SubjId)
);
【问题讨论】:
-
每单位的总价格令人困惑。我认为应该是总价或单价
-
问题 4 和 5 的英语不及格。给您一个单价,并要求您找到一个总单价,这将是单个单价。我希望提问者要求的是每个主题的总价格(这将是单位数乘以单位价格),但他们没有要求。
-
这两个问题似乎都不需要聚合函数来解决。
标签: sql oracle ddl sql-view dml