这是我创建的表:
CREATE TABLE Plane_new (Pnum char(3), Feature varchar2(20), Ptype varchar2(15),
primary key (Pnum));
CREATE TABLE Employee_new (eid char(3), ename varchar(10), salary number(7,2), mid char(3),
PRIMARY KEY (eid), FOREIGN KEY (mid) REFERENCES Employee_new);
CREATE TABLE Pilot_new (eid char(3), Licence char(9), primary key (eid),
foreign key (eid) references Employee_new on delete cascade);
CREATE TABLE FlightI_new (Fnum char(4), Fdate date, Duration number(2), Pid char(3),
Pnum char(3), primary key (Fnum), foreign key (Pid) references Pilot_new (eid),
foreign key (Pnum) references Plane_new);
这是我必须完成的查询:对于每个航班,显示其编号、执行该航班的飞行员的姓名,如果飞行持续时间长于平均水平或“短于平均水平”,则显示“长于平均”字样如果飞行时间短于或等于平均值。对于包含“长于平均值”或“短于平均值”的列,请制作标题长度。
这是我想出的-没有运气!
SELECT F.Fnum, E.ename,
CASE Length
WHEN F.Duration>(SELECT AVG(F.Duration) FROM FlightI_new F)
THEN "Longer than average"
WHEN F.Duration<=(SELECT AVG(F.Duration) FROM FlightI_new F)
THEN 'Shorter than average' END
FROM FlightI_new F LEFT OUTER JOIN Employee_new E ON F.Pid=E.eid
GROUP BY F.Fnum, E.ename;
我哪里错了?