The Question
SQLIdentifying Middle Management Tiers
Given a corporate reporting structure where some employees manage others, identify 'Senior Managers'. A Senior Manager is defined as someone who manages at least one person who is also a manager, provided that none of their direct reports are themselves Senior Managers. For all such individuals, calculate the total number of their direct reports and return the list sorted by the largest organization size.
PostgreSQL
Window Functions
CTE
NOT EXISTS
Self-Join
Set Operations
March 4, 2026