简体   繁体   中英

SQL movie database querying

I'm having trouble solving the following SQL requests:

  1. Give the names of the actors that have acted in more films than 'sara allgood' and who have acted in films that won the 'cannes film festival'. Also, give the filmname.

  2. Get the percentage of movies who won awards out of all movies produced between the years 1970 and 1990.

There are several tables but I'm assuming that only 4 are needed: 'films','remakes','casts', 'awtypes'

  • 'films' attributes: filmid, filmname, year, director, studio, award

  • 'remakes' attributes: filmid, title, year, priorfilm, prioryear

  • 'casts' attributes: filmid, filmname, actor, award(10)

  • 'awtypes' attributes: award(10), org(100), country, colloquial(50), year

It's a bit unclear to me how to match the award to the 'Cannes film festival' in the first query since the award field is only 10 characters meaning it is a reference to the awtypes table but I don't know which field in the awtypes table contains the name of the award and I don't have access to the database at the moment so it's either org or colloquial.

As for the second I don't know how I could compute the percentage but it seems that it should be solved using a union operator for the movies produced between 1970 and 1990 and the films that have won an award (I don't know how to place a condition for having at least one award).

A few hints, I hope they help you!

Give the names of the actors that have acted in more films than 'sara allgood' and who have acted in films that won the 'cannes film festival'. Also, give the filmname.

Based on the attributes you're stating, I would say that you can get to the right awtypes attribute via the casts table. They both contain the award(10) column. Given your data, I would expect the org(100) column to contain something on the organization that provides the prizes, so that would be my guess in this case for the cannes film festival content. But you would have to try it out and see what results you get. Unfortunately, as in this case, it is often quite hard to guess the contents of a column based only on column names.

Get the percentage of movies who won awards out of all movies produced between the years 1970 and 1990.

Based on the info stated in your question, I would go with a guess that the award column in the films table contains a boolean or something that states if the movie won an award or not. You'd have to try this out. If that's the case, you can use a COUNT(*) on all movies between 1970 and 1990 and a COUNT(*) on all movies WHERE award = 1 (or something) to get the total numbers.

You could indeed combine these in a computation query with a UNION . Example that might help you:

SELECT   SUM(cnt1) / SUM(cnt2) ... do the right computation here ...
FROM     ( SELECT  COUNT(*) AS cnt1
                   ,0 AS cnt2
           FROM    table1

           UNION ALL

           SELECT  0 AS cnt1
                   ,COUNT(*) AS cnt2
           FROM    table2) AS sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM