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
Host Revenue Running Total
00:00
5 left

Host Revenue Running Total

MediumSQL · PostgreSQL

Problem

Write a query using window functions to calculate the running total of revenue generated per host, resetting the count at the start of each calendar year.

Use the hosts and trips tables. Include completed trips only. The running total must be chronological within each host and year, with trip_id as the tie-breaker for trips on the same date.

Output

  1. One row per completed trip with a matching host
  2. Columns: host_id, host_name, calendar_year, trip_id, trip_date, revenue, and running_total
  3. Sort by host_id, calendar_year, trip_date, and trip_id

Schema

hosts
ColumnTypeDescription
host_idPKINTUnique identifier for a host
host_nameVARCHAR(100)Display name of the host
trips
ColumnTypeDescription
trip_idPKINTUnique identifier for a trip
host_idINTHost associated with the trip
trip_dateDATEDate the trip was completed or recorded
revenueNUMERIC(10,2)Revenue attributed to the trip
statusVARCHAR(20)Trip processing status
Tableshoststrips
Interviewer

Your question is Host Revenue Running Total. 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.