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 Events Per City SQL
00:00
5 left

Top Events Per City SQL

MediumSQL · PostgreSQL

Problem

A ticket marketplace wants to identify the most searched events in each city. Write a SQL query to find the top three events per city based on ticket searches recorded during the thirty-day period ending on September 15, 2026.

Output

  1. Return one row per qualifying event with the columns city, event_id, event_name, search_count, and city_rank.
  2. Include only searches from August 16, 2026 through September 15, 2026, inclusive. Ignore searches whose event cannot be identified.
  3. Rank events independently within each city by descending search count. Break ties by ascending event_id, and return only the first three events per city.
  4. Sort the final results by city, then city_rank, then event_id.

Schema

events
ColumnTypeDescription
event_idPKINTUnique event identifier
event_nameVARCHAR(150)Name of the event
cityVARCHAR(80)City where the event takes place
ticket_searches
ColumnTypeDescription
search_idPKINTUnique ticket search identifier
event_idINTEvent searched for, when available
searched_atTIMESTAMPTimestamp when the search occurred
Tableseventsticket_searches
Interviewer

Your question is Top Events Per City 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.