Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Self Joins and Explode
00:00
5 left

SQL Self Joins and Explode

MediumSQL · PostgreSQL

Problem

Write SQL and PySpark transformations using self-joins, split, explode, and group-by aggregations. Use the employees table and include only active direct reports with non-empty tags.

Output

  1. One row per manager and tag, with manager_id, manager_name, tag, direct_report_count, and total_salary.
  2. Include unmatched manager IDs as Unknown manager.
  3. Order by manager_id, then normalized tag.

Schema

employees
ColumnTypeDescription
employee_idPKINTUnique employee identifier
employee_nameVARCHAR(100)Employee full name
manager_idINTEmployee ID of the direct manager
skill_tagsVARCHAR(255)Comma-separated employee skill tags
annual_salaryDECIMAL(12,2)Annual employee salary
is_activeBOOLEANWhether the employee is active
Tablesemployees
Interviewer

Your question is SQL Self Joins and Explode. Start with the requirements and the one table 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.