← All tasksSQL · Junior

Filter and sort

List employees of the Engineering department with a salary above 5000: columns name and salary.

Highest salaries first, and for equal salaries by name alphabetically.

Tables

CREATE TABLE employees (
  id         int PRIMARY KEY,
  name       text NOT NULL,
  department text NOT NULL,
  salary     int NOT NULL
);

Tests (3)

Each test fills the tables with its own data and compares your query's result with the expected one: the same columns (names and order) and the same rows in the same order, so ORDER BY matters. The query runs in real PostgreSQL right in your browser; the first run downloads it (about 5 MB).

  1. INSERT INTO employees VALUES
      (1, 'Ann', 'Engineering', 7000),
      (2, 'Bob', 'Sales', 9000),
      (3, 'Cid', 'Engineering', 4000),
      (4, 'Dee', 'Engineering', 8000);
  2. -- equal salaries: sorted by name
    INSERT INTO employees VALUES
      (1, 'Zoe', 'Engineering', 6000),
      (2, 'Max', 'Engineering', 6000),
      (3, 'Eva', 'Engineering', 5000);
  3. -- nobody matches
    INSERT INTO employees VALUES
      (1, 'Ann', 'Sales', 9000),
      (2, 'Bob', 'Engineering', 5000);