Skip to content

Commit

Permalink
Create Julie Andrews method
Browse files Browse the repository at this point in the history
  • Loading branch information
genxhero committed Sep 4, 2018
1 parent 26f2c76 commit a68e1a4
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions skeleton/lib/07_joins_exercises.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ def example_join
def ford_films
# List the films in which 'Harrison Ford' has appeared.
execute(<<-SQL)
SELECT
title
FROM
movies
JOIN
castings ON movies.id = castings.movie_id
JOIN
actors ON castings.actor_id = actors.id
WHERE
actors.name = 'Harrison Ford'
SQL
end

Expand All @@ -48,26 +58,79 @@ def ford_supporting_films
# role. [Note: the ord field of casting gives the position of the actor. If
# ord=1 then this actor is in the starring role]
execute(<<-SQL)
SELECT
title
FROM
movies
JOIN
castings ON movies.id = castings.movie_id
JOIN
actors ON castings.actor_id = actors.id
WHERE
actors.name = 'Harrison Ford' AND castings.ord != 1
SQL
end

def films_and_stars_from_sixty_two
# List the title and leading star of every 1962 film.
execute(<<-SQL)
SELECT
title, name
FROM
movies
JOIN
castings ON movies.id = castings.movie_id
JOIN
actors ON castings.actor_id = actors.id
WHERE
movies.yr = 1962 AND castings.ord = 1
SQL
end

def travoltas_busiest_years
# Which were the busiest years for 'John Travolta'? Show the year and the
# number of movies he made for any year in which he made at least 2 movies.
execute(<<-SQL)
SELECT
yr, COUNT(*)
FROM
movies
JOIN
castings ON movies.id = castings.movie_id
JOIN
actors ON castings.actor_id = actors.id
WHERE
actors.name = 'John Travolta' GROUP BY yr
HAVING COUNT(*) >= 2
SQL
end

def andrews_films_and_leads
# List the film title and the leading actor for all of the films 'Julie
# Andrews' played in.
execute(<<-SQL)
SELECT
title, name
FROM
movies
JOIN
castings ON movies.id = castings.movie_id
JOIN
actors ON castings.actor_id = actors.id
WHERE movies.id IN (
SELECT
movies.id
FROM
movies
JOIN
castings ON castings.movie_id = movies.id
JOIN
actors on actors.id = castings.actor_id
WHERE
actors.name = 'Julie Andrews'
) AND castings.ord = 1
ORDER BY
movies.title
SQL
end

Expand Down

0 comments on commit a68e1a4

Please sign in to comment.