#390 Departments with a Small Number of Employees

Companies:
X5
Themes:
SQLAggregationPractice

Display the departments whose employee count does not exceed three:

- Department:
CREATE TABLE department (
  id   INTEGER      NOT NULL, - department identifier
  name VARCHAR(128) NOT NULL, - department name
  PRIMARY KEY (id)
);

- Employee:
CREATE TABLE employee (
  id            INTEGER      NOT NULL, - employee identifier
  department_id INTEGER      NOT NULL, - department identifier
  manager_id    INTEGER,               - manager identifier
  name          VARCHAR(128) NOT NULL, - employee name
  salary        DECIMAL      NOT NULL, - employee salary
  PRIMARY KEY (id),
  FOREIGN KEY (department_id) REFERENCES department(id),
  FOREIGN KEY (manager_id) REFERENCES employee(id)
);

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in