Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Query for Favorite Genre Actors
00:00
5 left

Query for Favorite Genre Actors

MediumSQL · PostgreSQL

Problem

Given tables WatchedMovies(movie_id, genre), MovieActors(movie_id, actor_id), GenreActors(genre, actor_id) and Actors(actor_id, age), write a SQL query to find the actors you would be interested in based on your favorite genre (the genre for which you have watched the most movies). Return their actor_id and age, sorted by age in descending order.

Asked in the Round 1: coding stage. Senior Data Scientist, Bengaluru.

Output

  1. Return actor_id and age, with one row per matching actor.
  2. Use the genre with the greatest number of watched movies. Ignore NULL genres and actors whose age is NULL.
  3. Sort by age descending, then actor_id ascending to break ties.

Schema

WatchedMovies
ColumnTypeDescription
movie_idPKINTIdentifier of a watched movie
genreVARCHAR(50)Movie genre
GenreActors
ColumnTypeDescription
genreVARCHAR(50)Genre associated with the actor
actor_idINTIdentifier of an actor associated with the genre
Actors
ColumnTypeDescription
actor_idPKINTUnique actor identifier
ageINTActor age in years
TablesWatchedMoviesGenreActorsActors
Interviewer

Your question is Query for Favorite Genre Actors. Start with the requirements and the three tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.