我的桌子是:
CREATE TABLE Rating
(
rid INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
mid INTEGER FOREIGN KEY REFERENCES Movie(movieId) ON DELETE CASCADE,
uid INTEGER FOREIGN KEY REFERENCES User(id) ON DELETE CASCADE,
rating INTEGER NOT NULL,
);
我想选择平均评分最高的中档:
select avg(r.rating) from rating r
女巫返回平均值。我想返回平均评分最高的中档。任何想法如何做到这一点?
> 更新
另外两个表:
CREATE TABLE User(
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
passwordhash VARCHAR(100) NOT NULL,
fullname VARCHAR(50) NOT NULL,
birthday DATE NOT NULL,
joindate DATE NOT NULL,
email VARCHAR(50) NOT NULL,
picturepath VARCHAR(256) NOT NULL,
favouritemovie VARCHAR(50) NOT NULL,
favouritecategory INTEGER REFERENCES category(id),
isDeleted BOOLEAN NOT NULL
);
CREATE TABLE Movie
(
movieId INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
title VARCHAR(255) NOT NULL,
moviePath VARCHAR(500) NOT NULL
);