Rank employees by salary within each department using window functions.
Toolliyo Coach
Progressive help: Nudge → Guide → Approach. Full solution stays behind the Solution tab.
Editor is open — no login wall to practice.
| Test | Status | Details |
|---|
Ready — edit the code above and click Run or Submit.
-- PostgreSQL schema
CREATE TABLE employees (id SERIAL PRIMARY KEY, name TEXT, dept_id INT, salary NUMERIC(10,2));
CREATE TABLE departments (id SERIAL PRIMARY KEY, name TEXT);
INSERT INTO employees (name, dept_id, salary) VALUES ('Ali',1,90000),('Sara',2,120000);
INSERT INTO departments (name) VALUES ('Engineering'),('Sales');
SELECT name, salary, dept_id,
ROW_NUMBER() OVER (PARTITION BY dept_id ORDER BY salary DESC) AS rn
FROM employees;
Prefer Coach (Nudge → Guide → Approach) before revealing. No forced signup.
Window functions: PARTITION BY groups, ORDER BY ranks within group.
Sign in to save and review your submission history. You can still Run code on the Editor tab as a guest.
Sign in