Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
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 feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Top 3 Per Category SQL
00:00
5 left

Top 3 Per Category SQL

EasySQL · PostgreSQL

Problem

Cotality Property Insights needs a ranked view of active properties for market analysis. Write a PostgreSQL query that returns the top three properties by estimated market value within each active property category.

Requirements

  1. Join property_listings to property_categories using category_id.
  2. Include only active listings with a non-null estimated market value and active categories.
  3. Rank properties independently within each category by estimated market value descending. Break ties with listing_id ascending.
  4. Return only ranks 1 through 3, ordered by category name and rank.

Schema

property_categories
ColumnTypeDescription
category_idPKINTUnique property category identifier
category_nameVARCHAR(100)Display name of the property category
is_activeBOOLEANWhether the category is active in Cotality Property Insights
property_listings
ColumnTypeDescription
listing_idPKINTUnique property listing identifier
category_idINTReferenced property category identifier
addressVARCHAR(200)Property street address
estimated_market_valueNUMERIC(12,2)Estimated market value of the property
valuation_dateDATEDate on which the estimate was produced
listing_statusVARCHAR(30)Current listing status
Tablesproperty_categoriesproperty_listings
Interviewer

Your question is Top 3 Per Category SQL. Start with the requirements and the two 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.