You may make a copy of a worksheet and complete this activity, or simply type your answers in any text editor.
You may work alone or with 3-4 students in this course (max size=5).
Given the following relations and schemas, write SQL queries to solve the problems.
Movies (title, year, length, genre, studioName, producerCert) starsIn (movieTitle, movieYear, starName, salary) MovieStar (name, address, gender, birthdate) MovieExec (name, address, producerCert, netWorth) Studio (name, address)
SELECT address AS Studio_Address FROM Studio WHERE name = "MGM";
SELECT COUNT(*) FROM Movies WHERE studioName <> "MGM";
SELECT starName
FROM StarsIn
WHERE movieYear = 2023 OR
movieTitle LIKE "%Love%";
However, the above query will also return words that have the substring Love e.g. Lover.
Below query will only return movies that have title containing the word Love.
SELECT starName
FROM StarsIn
WHERE movieYear = 2023 OR
movieTitle LIKE "Love %" OR
movieTitle LIKE "% Love %" OR
movieTitle LIKE "% Love" OR movieTitle = "Love";
SELECT name FROM MovieExec WHERE 5000000 <= netWorth AND netWorth <= 10000000; Another solution: SELECT name FROM MovieExec WHERE netWorth BETWEEN 5000000 AND 10000000;
SELECT name AS Star_Name FROM movieStar WHERE gender = "F" OR address LIKE '%Malibu%'; // '% Malibu %' ?
SELECT M.name AS starName
FROM MovieStar M,
StarsIn S
WHERE M.name = S.starName AND
S.movieTitle = "Star Wars" AND
M.gender = "M";
Assuming the same movie title may be made in multiple years
SELECT S.starName AS starName
FROM Movies M,
starsIn S
WHERE M.title = S.movieTitle AND
M.year = S.movieYear AND
M.year = 2023 AND
M.studioName = 'MGM'
SELECT DISTINCT MovieStar.address
FROM MovieStar, MovieExec
WHERE MovieStar.address LIKE "%Malibu%" AND
MovieStar.address = MovieExec.address
Another possible solution:
(SELECT address
FROM MovieStar
WHERE address LIKE '%Malibu%')
INTERSECT
(SELECT address
FROM MovieExec
WHERE address LIKE '%Malibu%')
CC-BY-NC-SA 4.0 license.