Departments with more than three people

SQL data engineering interview problem. Difficulty: beginner. Pattern: Aggregation. About 8 minutes. Free to practice.

Small teams are hard to manage as a group, so HR wants to see only the bigger ones. Find every department in the employees table that has more than 3 employees. Return 2 columns: department and employee_count. Ignore employees who have no department. Show the biggest departments first, and sort by department name when two have the same size.

Requirements

  • Count the employees in each department.
  • Keep only the departments where that count is greater than 3. A department with exactly 3 people does not qualify.
  • Use HAVING for this filter, because the count only exists after the rows are grouped.
  • Sort by employee_count from high to low, then by department from A to Z.

Constraints

  • The table is employees.
  • Return only these 2 columns, in this order: department, employee_count.
  • Rows where department is NULL are ignored.

Examples

Input: employees department | rows Engineering | 4 Sales | 2 Output: department | employee_count Engineering | 4 Why this passes: Sales has 2, which fails > 3. Only Engineering clears the bar.

Topics: lakebench, sql, having, group by.

More SQL interview questions · All interview problems · Learn data engineering

beginner

Departments with more than three people

Interview-style drill: HAVING filter for departments larger than 3 employees.

Find departments with more than 3 employees. Return `department` and `employee_count`. Ignore NULL departments. Order by `employee_count` descending, then `department`.