Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Joins and Date Aggregation

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL Joins and Date Aggregation. Start with the requirements and the three tables on the right.

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.

Problem

Agile Defense's mission support dashboard needs a daily summary of operational events across missions and monitored systems. Write a PostgreSQL query that joins mission events to their mission and system records, then aggregates the results by event date and mission.

Requirements

  1. Restrict results to events from April 1 through April 4, 2025, inclusive.
  2. Return the event date, mission code, mission name, total event count, completed event count, distinct systems involved, and total impact score.
  3. Use a LEFT JOIN for systems so events remain visible when a system record is unavailable. Treat a missing impact score as zero.
  4. Return only date and mission groups with more than one event, ordered by date and mission code.

Schema

missions
ColumnTypeDescription
mission_idPKINTEGERPrimary key for a mission
mission_codeVARCHAR(20)Short mission identifier
mission_nameVARCHAR(100)Mission display name
mission_events
ColumnTypeDescription
event_idPKINTEGERPrimary key for an event
mission_idINTEGERReferences missions.mission_id
system_idINTEGERReferences systems.system_id when available
event_recorded_atTIMESTAMPTimestamp when the event was recorded
statusVARCHAR(20)Current event status
impact_scoreINTEGERNumeric impact score
systems
ColumnTypeDescription
system_idPKINTEGERPrimary key for a monitored system
system_nameVARCHAR(100)System display name
system_categoryVARCHAR(50)System classification
Tablesmissionsmission_eventssystems
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results