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
Build January 2025 Account Event Aggregates
00:00
5 left

Build January 2025 Account Event Aggregates

MediumSQL · PostgreSQL

Problem

Describe your process for modeling data for a new analytical use case.

Use source_accounts and source_events to produce a reusable account-level analytical result. Include accounts without qualifying events, exclude events outside January 2025 or without a timestamp, and preserve null source attributes.

Output

  1. One row per account, ordered by account_id ascending.
  2. Columns: account_id, account_name, region, event_count, successful_event_count, total_value, and first_event_at.
  3. Counts and total value must be zero when an account has no qualifying events; first_event_at must remain NULL.

Output details

  • Count an event as successful only when outcome equals success.
  • Include timestamps from 2025-01-01 00:00:00 inclusive through 2025-02-01 00:00:00 exclusive.
  • Ignore NULL value entries when summing, returning numeric zero when all qualifying values are NULL.

Schema

source_accounts
ColumnTypeDescription
account_idPKINTStable source identifier for an account
account_nameVARCHAR(100)Account display name
regionVARCHAR(50)Optional account region
created_atDATEDate the account was created
source_events
ColumnTypeDescription
event_idPKINTUnique source event identifier
account_idINTAccount associated with the event
event_tsTIMESTAMPTimestamp when the event occurred
event_typeVARCHAR(40)Source event classification
outcomeVARCHAR(20)Result of the event
valueNUMERIC(12,2)Optional numeric event value
Tablessource_accountssource_events
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two tables are in the Question tab.

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.