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.)
Database: coursera assignment 1的更多相关文章
- JavaScript 编码小技巧
三元操作符 如果使用if...else语句,那么这是一个很好节省代码的方式. Longhand: const x = 20; let answer; if (x > 10) { answer = ...
- 19 个 JavaScript 编码小技巧
这篇文章适合任何一位基于JavaScript开发的开发者.我写这篇文章主要涉及JavaScript中一些简写的代码,帮助大家更好理解一些JavaScript的基础.希望这些代码能从不同的角度帮助你更好 ...
- 19个JavaScript简化编码小技巧
这篇文章适合任何一位基于JavaScript开发的开发者.我写这篇文章主要涉及JavaScript中一些简写的代码,帮助大家更好理解一些JavaScript的基础.希望这些代码能从不同的角度帮助你更好 ...
- 盘点Mysql的登陆方式
前置知识 我们想登陆到mysql中前提是肯定需要一个用户名和密码:比如 root root 在mysql中用户的信息会存放在 mysql数据库下的 user表中 可以 use mysql 然后sele ...
- 白日梦的MySQL专题(第33篇):各种登陆MySQL的骚操作
阅读原文 系列文章公众号首发,点击阅读原文 前置知识 我们想登陆到mysql中前提是肯定需要一个用户名和密码:比如 mysql -uroot -proot 在mysql中用户的信息会存放在 mysql ...
- 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 ...
- 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 ...
- 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 ...
- coursera普林斯顿算法课part1里Programming Assignment 2最后的extra challenge
先附上challenge要求: 博主最近在刷coursera普林斯顿大学算法课part1部分的作业,Programming Assignment2最后的这个extra challenge当初想了一段时 ...
随机推荐
- 2017.2.16 开涛shiro教程-第十七章-OAuth2集成(一)服务器端
原博客地址:http://jinnianshilongnian.iteye.com/blog/2018398 根据下载的pdf学习. 开涛shiro教程-第十七章-OAuth2集成 1.OAuth2介 ...
- 一群牛人翻译:The Swift Programming Language 中文版
无聊闲逛GIthub,看到一群牛人在github上创建了一个关于Switf的文档翻译项目 The Swift Programming Language 中文版 项目地址:中文版 Apple 官方 Sw ...
- mysql if()一个奇怪的问题
看起来一切正常......... 但是当使用不等于时 SELECT IF(1!=NULL,1,2) 居然返回2 SELECT IF(1!=NULL,1,2) >2 -- ------------ ...
- 『HTML5梦幻之旅』 - 仿Qt演示样例Drag and Drop Robot(换装机器人)
起源 在Qt的演示样例中看到了一个有趣的demo.截图例如以下: 这个demo的名字叫Drag and Drop Robot,简单概括而言,在这个demo中,能够把机器人四周的颜色拖动到机器人的各个部 ...
- ES6使用箭头函数注意点
新事物也是有两面性的,箭头函数有他的便捷有他的优点,但是他也有缺点,他的优点是代码简洁,this提前定义,但他的缺点也是这些,比如代码太过简洁,导致不好阅读,this提前定义,导致无法使用JS进行一些 ...
- chm文件打不开的解决办法
我今天在网上找了找C++函数库,下载下来一个 .chm 文件,打开之后发现只显示了目录,内容却显示不出来. 显示是这样:右边区域显示不出来. 在网上查了一下发现CHM文件是网上比较多的电子书籍显示格式 ...
- Redis(九):使用RedisTemplate访问Redis数据结构API大全
RedisTemplate介绍 spring封装了RedisTemplate对象来进行对redis的各种操作,它支持所有的 redis 原生的api. RedisTemplate在spring代码中的 ...
- Codeforces 223C Partial Sums 数论+组合数学
题意非常easy,求不是那么好求的,k非常大 要操作非常多次,所以不可能直接来的.印象中解决操作比較多无非线段树 循环节 矩阵 组合数等等吧,这道题目 也就仅仅能多画画什么 的了 就以第一个案例为主吧 ...
- 数据挖掘之Slope One
计算偏差: card() 表示集合包含的元素数量. http://www.cnblogs.com/similarface/p/5385176.html 论文地址:http://lemire.me/fr ...
- GenericServlet 、Servlet和httpServler他们之间的关系
1.GenericServlet类是所有Servlet类的祖先类. 2.HttpServlet类继承了GenericServlet类. 3.Servlet有两个非常重要的的对象,可以说是java we ...