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
Hard SQL With Window Functions
00:00
5 left

Hard SQL With Window Functions

HardSQL · PostgreSQL

Problem

Sum(case when attribute is true) Unions Hard SQL using window functions Python leetcode Easy

Use the provided entity and event tables. Combine the two event sources, remove exact duplicate records, and analyze events from January through March 2025.

Output

  1. One row per entity and calendar month with events
  2. Return entity_id, entity_name, month_start, event count, true-attribute count, prior-month true count, cumulative true count, and rank by monthly true count
  3. Sort by entity_id, then month_start

Schema

entities
ColumnTypeDescription
entity_idPKINTUnique entity identifier
entity_nameVARCHAR(100)Entity display name
current_entity_events
ColumnTypeDescription
event_idPKINTUnique event identifier within the source
entity_idINTReferenced entity
event_tsTIMESTAMPEvent timestamp
attribute_is_trueBOOLEANWhether the event attribute is explicitly true
archived_entity_events
ColumnTypeDescription
event_idPKINTUnique event identifier within the source
entity_idINTReferenced entity
event_tsTIMESTAMPEvent timestamp
attribute_is_trueBOOLEANWhether the event attribute is explicitly true
Tablesentitiescurrent_entity_eventsarchived_entity_events
Interviewer

Your question is Hard SQL With Window Functions. Start with the requirements and the three 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.