獲取收視率最高的電影,我有三個表:SQL - 按流派
CREATE TABLE Movie
(
movieId INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
title VARCHAR(255) NOT NULL,
moviePath VARCHAR(500) NOT NULL
);
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,
);
CREATE TABLE Genre(
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
movieId INTEGER NOT NULL FOREIGN KEY REFERENCES Movie(movieId) ON DELETE CASCADE,
genre VARCHAR(255) NOT NULL
);
我想創建從最多見於類型的SQL查詢,給了我最多見於電影(與moviepath,標題)回。
任何想法?
UPDATE
結果:
| MID | TITLE | MOVIEPATH |
--------------------------------
| 4 | Happy days | a |
| 4 | Happy days | a |
我想'movieId'不應該在'Genre'表,但一個'GenreId'應該是'Movie'表。而你的表格對於這樣的查詢是不完整的,你需要一些額外的細節。 –
你是什麼意思? – maximus
與您當前的表中每個類型可以有一個電影,但與我告訴每個電影有一個流派的表格。 –