前幾天我問過類似的問題,這是我的問題。我的教授解釋了以下問題:找出每個劇院中所有電影的平均收視率。顯示劇院名稱和計算出的評分。按等級升序排列結果。對SQL查詢的後續幫助
這裏是我的表是如何構成的:
CREATE TABLE Theatres (
Name varchar2(50) not null,
City varchar2(50) not null,
State varchar2(50) not null,
Zip number not null,
Phone varchar2(50) not null,
PRIMARY KEY (Name)
);
CREATE TABLE Movies (
Title varchar2(100) not null,
Rating NUMBER not null,
Length NUMBER not null,
ReleaseDate date not null,
PRIMARY KEY (Title),
CHECK (Rating BETWEEN 0 AND 10),
CHECK (Length > 0),
CHECK (ReleaseDate > to_date('1/January/1900', 'DD/MONTH/YYYY'))
);
CREATE TABLE ShownAt (
TheatreName varchar2(50) not null,
MovieTitle varchar2(100) not null,
PRIMARY KEY (TheatreName, MovieTitle),
FOREIGN KEY (TheatreName) REFERENCES Theatres(Name),
FOREIGN KEY (MovieTitle) REFERENCES Movies(Title)
);
SELECT
AVG(Movies.Rating),
Theatres.Name
FROM Theatres
JOIN ShownAt ON ShownAt.TheatreName = Theatres.Name
JOIN Movies ON ShownAt.MovieTitle = Movies.Title
ORDER BY Movies.Rating ASC
看到什麼與衆不同?我不斷收到一個錯誤,指出SQL錯誤:ORA-00937:不是單組功能00937. 00000 - 「不是單組功能」。原諒我的初學者。
即使與(我的例子中瞭解到,我一直在關注你的過去例如)我仍然得到一個「SQL命令沒有正確結束」 – 2010-09-12 00:31:31
你用分號結束它? 「GROUP BY」和「ORDER BY」是否正確? – 2010-09-12 00:34:19