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
SQL Ranking by Satisfaction
00:00
5 left

SQL Ranking by Satisfaction

MediumSQL · PostgreSQL

Problem

Write a SQL query to rank hotels by guest satisfaction score within each region and return the top 3 per region.

Use the provided hotel, region, and guest review data. Guest satisfaction is the average non-null review score for each hotel. Hotels without a valid score should be excluded. Ties share the same rank, so a region may return more than three hotels.

Output

  1. One row per qualifying hotel, with region_name, hotel_name, guest_satisfaction_score, and satisfaction_rank
  2. Include only hotels ranked 1 through 3 within their region
  3. Order by region_name, satisfaction_rank, then hotel_name

Schema

regions
ColumnTypeDescription
region_idPKINTUnique region identifier
region_nameVARCHAR(100)Region name
hotels
ColumnTypeDescription
hotel_idPKINTUnique hotel identifier
hotel_nameVARCHAR(150)Hotel name
region_idINTReferenced region identifier
guest_reviews
ColumnTypeDescription
review_idPKINTUnique guest review identifier
hotel_idINTReferenced hotel identifier
scoreDECIMAL(3,2)Guest satisfaction score from 1.00 to 5.00
Tablesregionshotelsguest_reviews
Interviewer

Your question is SQL Ranking by Satisfaction. 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.