Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Join and Monthly Summary
00:00
5 left

SQL Join and Monthly Summary

MediumSQL · PostgreSQL

Problem

Write a SQL query to join multiple tables and calculate a monthly summary of analyst-relevant metrics.

Use the provided analyst, activity, and target tables. Include activity from January through March 2025 and preserve months that have activity but no matching target.

Output

  1. One row per analyst and activity month
  2. Columns: analyst_name, month_start, activity_count, completed_count, total_metric_value, average_metric_value, target_value, attainment_percentage
  3. Include all activity records in the period, including records with null metric values
  4. Order by analyst_id, then month_start

Schema

analysts
ColumnTypeDescription
analyst_idPKINTUnique analyst identifier
analyst_nameVARCHAR(100)Analyst display name
regionVARCHAR(50)Analyst reporting region
active_flagBOOLEANWhether the analyst is currently active
analyst_activity
ColumnTypeDescription
activity_idPKINTUnique activity identifier
analyst_idINTReferences analysts.analyst_id
activity_dateDATEDate when the activity occurred
activity_typeVARCHAR(50)Type of analyst activity
statusVARCHAR(30)Current activity status
metric_valueDECIMAL(12,2)Numeric value associated with the activity
monthly_targets
ColumnTypeDescription
target_idPKINTUnique monthly target identifier
analyst_idINTReferences analysts.analyst_id
target_monthDATEFirst day of the target month
target_valueDECIMAL(12,2)Target metric value for the month
Tablesanalystsanalyst_activitymonthly_targets
Interviewer

Your question is SQL Join and Monthly Summary. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.