Ajvree Week 6

From LMU BioDB 2013
Jump to: navigation, search

1.What movies were released before 1915?
select * from movie where year < 1915
DW Griffith, Lumiere Brother.., Tillie's Punctu.., Cabiria

2.What movies from the 1980s had 4-digit numbers in their titles? select * from movie where title ~ '[0123456789][012356789][0123456789][0123456789]' and year >= 1980 and year < 1990
Cherry 2000, 2010: The Year.., 1984, Cold Summer of.., Butthole Surfers.., Gundam 0080.., Transylvania 6.., Hong Kong 1941, 1969, Mystery Science.., Eric Clapton.., the 2000 year..., Teenage Mutant..

3.What movies have apostrophes in their titles?
select * from movie where title like '%'%'
There were many results, count 1280


4.How many movies have titles that begin with the word “Star”?
select count(*) from movie where title ~ '^Star'
88 results


5.How many movies, on a year by year basis, were released in the 1940s (years 1940 to 1949)? (don’t answer this question by listing the movies then counting the results!)
select year, count(*) from movie where year > 1940 and year < 1950 group by year
1942- 33
1948- 36
1943- 33
1946- 39
1945- 37
1947- 37
1944- 36
1941- 33


6.Which movies, in alphabetical order, did member number 42 rate as a “5”?
select title, rating from movie inner join rating on (movie.id = rating.movie) where member = 42 and rating = 5 order by title
Bruce Lee A Warriors Journey
Donnie Darko
The Legend of Zelda
Zatoichi's Conspiracy


7.Produce a table that lists every movie that has been rated, the rating that the movie got, and the name of the member that gave this rating. select title,rating,name from movie inner join rating on (rating.movie = movie.id) inner join member on (rating.member = member.id)

8.How many movies has member number 42 rated as 1, 2, 3, 4, and 5, respectively?
select title, rating from movie inner join rating on (movie.id = rating.movie) where member = 42 order by rating
1-1
2-0
3-2
4-3
5-4

9.What is the average rating of movies that begin with the word “Star”? select avg(rating) from movie inner join rating on (movie.id = rating.movie) where title ~ '^Star'
Average rating: 2.6

10.Form your own query involving movies, ratings, and members, then State your query in plain English (like the queries above).

Provide the SQL query "translation" of your plain English query.

Supply the answer to your query, according to the sample movie database.

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox