私のテーブルは次のとおりです。
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,
);
平均評価が最も高い mid を選択したい:
select avg(r.rating) from rating r
魔女は平均を返します。最も平均的な評価の mid`s を返したいです。それを行う方法はありますか?
> 更新
他の 2 つのテーブル:
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
);