About the “Top 2 Sales Reps per Region with DENSE_RANK()” SQL Problem
Business Scenario
Sales VP is allocating president club bonuses. They need to find the top 2 sales reps by total bookings in each geographic territory, properly handling ties.
Expected Output & Criteria
Filtered table with rep_name, region, total_bookings, and regional_rank containing only rank 1 and 2 reps per region.
Database Table Schema (PostgreSQL DDL)
PostgreSQL 16 WASMThis challenge executes directly against the following relational schema in your browser:
CREATE TABLE sales_reps (
rep_id INT PRIMARY KEY,
rep_name VARCHAR(80) NOT NULL,
region VARCHAR(30) NOT NULL,
total_bookings NUMERIC(10, 2) NOT NULL
);Target SQL Clauses & Operators
DENSE_RANKOVERPARTITION BY
Want more Window Functions practice?
Explore the full syllabus of 14 exercises, syntax guides, and interview pitfalls.