我有这些表:
- 电影(mID、片名、年份、导演)
- 审稿人(rID,姓名)
- 评级(rID、mID、星数、ratingDate)
和一些观点:
视图
LateRating
包含 2011 年 1 月 20 日之后的电影评分。视图包含电影 ID、电影名称、星数和评分日期。create view LateRating as select distinct R.mID, title, stars, ratingDate from Rating R, Movie M where R.mID = M.mID and ratingDate > '2011-01-20'
视图
HighlyRated
包含至少有 1 个评分高于 3 星的电影。该视图包含电影 ID 和电影标题。create view HighlyRated as select mID, title from Movie where mID in (select mID from Rating where stars > 3)
View
NoRating
包含数据库中没有评分的电影。该视图包含电影 ID 和电影标题。create view NoRating as select mID, title from Movie where mID not in (select mID from Rating)
这是我的数据集:https ://prod-c2g.s3.amazonaws.com/db/Winter2013/files/viewmovie.sql
我被要求编写一个代替触发器来更新视图 LateRating 的 stars 属性。这是我的方法。
CREATE trigger update_LateRating_title INSTEAD OF
UPDATE OF stars ON LateRating
BEGIN
UPDATE Rating SET stars = stars - 2
WHERE Rating.mID = old.mID
AND Rating.mID IN (SELECT stars FROM Rating WHERE stars > 2);
END;
它给出了几乎正确的答案,但只有一个错误的行是 201 101 4 2011-01-27.4 应该是 2。出了什么问题?