• Database: coursera assignment 1


    q.1: Find the titles of all movies directed by Steven Spielberg. 

    select title
    from movie
    where director = 'Steven Spielberg'

    q.2: Find all years that have a movie that received a rating of 4 or 5, and sort them in increasing order.

    select year
    from movie, rating
    where movie.mid = rating.mid and rating.stars >= 4
    group by movie.mid
    order by year

    q.3: Find the titles of all movies that have no ratings. 

    select title
    from movie, rating
    where movie.mid not in (select rating.mid from rating)
    group by movie.mid

    q.4: Some reviewers didn't provide a date with their rating. Find the names of all reviewers who have ratings with a NULL value for the date. 

    select name
    from reviewer re, rating ra
    where re.rid = ra.rid and ra.ratingdate is null

    q.5: Write a query to return the ratings data in a more readable format: reviewer name, movie title, stars, and ratingDate. Also, sort the data, first by reviewer name, then by movie title, and lastly by number of stars. 

    select name, title, stars, ratingdate
    from movie, reviewer, rating
    where movie.mid = rating.mid and reviewer.rid = rating.rid
    order by name, title, stars

    q.6: For all cases where the same reviewer rated the same movie twice and gave it a higher rating the second time, return the reviewer's name and the title of the movie. 

    select name, title
    from movie, reviewer, rating r1, rating r2
    where movie.mid = r1.mid and reviewer.rid = r1.rid and r1.mid = r2.mid and r1.rid = r2.rid and r1.stars < r2.stars and r1.ratingdate < r2.ratingdate

    q.7: For each movie that has at least one rating, find the highest number of stars that movie received. Return the movie title and number of stars. Sort by movie title. 

    select title, max(stars)
    from movie, rating
    where movie.mid = rating.mid
    group by rating.mid
    order by title

    q.8: For each movie, return the title and the 'rating spread', that is, the difference between highest and lowest ratings given to that movie. Sort by rating spread from highest to lowest, then by movie title. 

    select title, max(stars) - min(stars) as spread
    from movie, rating
    where movie.mid = rating.mid
    group by rating.mid
    order by spread desc, title

    q.9: Find the difference between the average rating of movies released before 1980 and the average rating of movies released after 1980. (Make sure to calculate the average rating for each movie, then the average of those averages for movies before 1980 and movies after. Don't just calculate the overall average rating before and after 1980.) 

  • 相关阅读:
    Linux下使用curl查看http请求各阶段耗时
    yum list查看版本
    【k8s】XX 修改ipvs模式
    域名访问时间 测试脚本
    关闭WINDOWS自动检测互联网络
    win10专业版安装VMware workstation pro 16时提示“setup failed to generate the ssl keys necessary to run vmware”笔记
    手动启动MegaRAID Storage Manager v17.05.02.01 for Linux
    Java基于POI实现excel任意多级联动下拉列表——支持从数据库查询出多级数据后直接生成【附源码】
    C# 后台POST数据及API接收简记
    Linux 安装pycharm,清除缓存,scp传输文件
  • 原文地址:https://www.cnblogs.com/yingzhongwen/p/3537516.html
Copyright © 2020-2023  润新知