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
ExperiencesCoaching
New
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
Get started
Running Totals for Event Counts
00:00
5 left

Running Totals for Event Counts

MediumSQL · PostgreSQL

Problem

How would you compute running totals for event counts?

Write a PostgreSQL query using discord_events and event_types. Ignore events with missing dates or event types that do not match a row in event_types.

Output

  1. One row per event type and event date.
  2. Columns: event_name, event_date, event_count, and running_total.
  3. running_total must include all events for that type through the displayed date.
  4. Order by event_name ascending, then event_date ascending.

Schema

event_types
ColumnTypeDescription
event_type_idPKINTUnique event type identifier
event_nameVARCHAR(100)Descriptive name of the event type
discord_events
ColumnTypeDescription
event_idPKINTUnique event identifier
event_type_idINTReferenced event type identifier
event_dateDATECalendar date on which the event occurred
Tablesdiscord_eventsevent_types
Interviewer

Your question is Running Totals for Event Counts. 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.