Solution

Databases

Problems to be Submitted (20 points)

  1. (6 points)
    1. TitleMovieId
      Field of Dreams104
      Alien105
      Elizabeth5022
      Platoon7442

    2. NameMovieIdDateRented
      Randy Wolf1043-12-2006
      Randy Wolf50223-12-2006
      Robert Person1073-12-2006

    3. TitleDateRented
      Field of Dreams3-12-2006
      Elizabeth3-12-2006

  2. (8 points)
    1.   SELECT name, population, area, gdp
        FROM bbc
        WHERE name='Belarus'
      

    2.   SELECT name, population, gdp
        FROM bbc
        WHERE region='Europe'
           OR region='Africa'
      

    3.   SELECT name, area, population
        FROM bbc
        WHERE population>1000*area
      

    4.   SELECT name, area
        FROM bbc
        WHERE region='Africa'
           AND (area<5000 OR area>1000000)
      

  3. (6 points)
    1.   SELECT title,score,votes
        FROM movie
        WHERE yr=1996
           AND score>=7.65
      

    2.   SELECT title,yr
        FROM movie,actor
        WHERE name='Mel Brooks'
           AND movie.director = actor.id
      

    3.   SELECT title
        FROM movie,actor,casting
        WHERE name='Mel Brooks'
           AND movie.director = actor.id
           AND movie.id = casting.movieid
           AND actor.id = casting.actorid
      


Extra Credit (4 points)

    1. Here is the list of IDs for movies which include Dan Aykroyd:

          SELECT movieid
          FROM casting,actor
          WHERE name = 'Dan Aykroyd'
            AND casting.actorid=actor.id
      

    2. Here is the complete SQL statement:

      SELECT title, yr
      FROM movie, casting, actor
      WHERE name='Chevy Chase'
        and casting.actorid=actor.id
        and casting.movieid=movie.id
        and movie.id IN
         (SELECT movieid
          FROM casting,actor
          WHERE name = 'Dan Aykroyd'
            AND casting.actorid=actor.id)
      


Last modified: Monday, 14 April 2008