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.)

Database: coursera assignment 1的更多相关文章

  1. JavaScript 编码小技巧

    三元操作符 如果使用if...else语句,那么这是一个很好节省代码的方式. Longhand: const x = 20; let answer; if (x > 10) { answer = ...

  2. 19 个 JavaScript 编码小技巧

    这篇文章适合任何一位基于JavaScript开发的开发者.我写这篇文章主要涉及JavaScript中一些简写的代码,帮助大家更好理解一些JavaScript的基础.希望这些代码能从不同的角度帮助你更好 ...

  3. 19个JavaScript简化编码小技巧

    这篇文章适合任何一位基于JavaScript开发的开发者.我写这篇文章主要涉及JavaScript中一些简写的代码,帮助大家更好理解一些JavaScript的基础.希望这些代码能从不同的角度帮助你更好 ...

  4. 盘点Mysql的登陆方式

    前置知识 我们想登陆到mysql中前提是肯定需要一个用户名和密码:比如 root root 在mysql中用户的信息会存放在 mysql数据库下的 user表中 可以 use mysql 然后sele ...

  5. 白日梦的MySQL专题(第33篇):各种登陆MySQL的骚操作

    阅读原文 系列文章公众号首发,点击阅读原文 前置知识 我们想登陆到mysql中前提是肯定需要一个用户名和密码:比如 mysql -uroot -proot 在mysql中用户的信息会存放在 mysql ...

  6. Coursera Deep Learning 2 Improving Deep Neural Networks: Hyperparameter tuning, Regularization and Optimization - week1, Assignment(Gradient Checking)

    声明:所有内容来自coursera,作为个人学习笔记记录在这里. Gradient Checking Welcome to the final assignment for this week! In ...

  7. Coursera Deep Learning 2 Improving Deep Neural Networks: Hyperparameter tuning, Regularization and Optimization - week1, Assignment(Initialization)

    声明:所有内容来自coursera,作为个人学习笔记记录在这里. Initialization Welcome to the first assignment of "Improving D ...

  8. Coursera Deep Learning 2 Improving Deep Neural Networks: Hyperparameter tuning, Regularization and Optimization - week1, Assignment(Regularization)

    声明:所有内容来自coursera,作为个人学习笔记记录在这里. Regularization Welcome to the second assignment of this week. Deep ...

  9. coursera普林斯顿算法课part1里Programming Assignment 2最后的extra challenge

    先附上challenge要求: 博主最近在刷coursera普林斯顿大学算法课part1部分的作业,Programming Assignment2最后的这个extra challenge当初想了一段时 ...

随机推荐

  1. C#是唯一能挑战Java的编程语言?

    几乎所有新近成长的Visual Studio代码开发人员都选择使用C#,而不是VB.NET或C++,这也使得C#已经成长为微软的第一大语言.根据本月的Tiobe编程语言排行榜,C#再次取得了突破性进展 ...

  2. Node.js学习入门手册

    Node.js 安装 1.下载http://nodejs.org/dist/v0.12.1/node-v0.12.1-x86.msi并完成安装 2.下载https://www.python.org/f ...

  3. 【oracle ocp知识点一】

    1.怎样确定数据库是否启动 su - oracle ps -ef |grep ora_|head -2 两种关系数据库是ora或者是自己主动存储管理的asm开头的, 查看进程能够知道数据库实例至少已经 ...

  4. Android源代码解析之(六)--&gt;Log日志

    转载请标明出处:一片枫叶的专栏 首先说点题外话,对于想学android framework源代码的同学,事实上能够在github中fork一份,详细地址:platform_frameworks_bas ...

  5. 让heigh:100%起作用

    如何让 height:100%; 起作用 http://www.webhek.com/css-100-percent-height     当你设置一个页面元素的高度(height)为100%时,期望 ...

  6. Mysql或者Hive数据行变成列

    对于mysql /  hive 再进行统计的时候假设须要行变成列,能够使用函数 CASE 字段a WHEN 值b THEN c [WHEN d THEN e]* [ELSE f] END 当字段a=值 ...

  7. Urho3D 在Win10下编辑器崩溃的解决方案

    本解决方案来自于 https://github.com/urho3d/Urho3D/issues/2417 描述 在Win10中通过CMake启用URHO_ANGELSCRIPT选项的前提下生成Urh ...

  8. 这样好用的ReactiveCocoa,根本停不下来【转载】

    前戏我个人非常推崇ReactiveCocoa,它就像中国的太极,太极生两仪,两仪生四象,四象生八卦,八卦生万物.ReactiveCocoa是一个高度抽象的编程框架,它真的很抽象,初看你不知道它是要干嘛 ...

  9. 史上最浅显易懂的Git教程2 github

    Git是分布式版本控制系统,同一个Git仓库,可以分布到不同的机器上.怎么分布呢?最早,肯定只有一台机器有一个原始版本库,此后,别的机器可以“克隆”这个原始版本库,而且每台机器的版本库其实都是一样的, ...

  10. 深入浅出Stream和parallelStream

    https://blog.csdn.net/darrensty/article/details/79283146