CoderPad provides a basic SQL sandbox with the following schema.
You can also use commands like show tables and desc <table_name>.
employees
id(int)first_name(varchar)last_name(varchar)salary(int)department_id(int)
departments
id(int)name(varchar)
projects
id(int)title(varchar)start_date(date)end_date(date)budget(int)
employees_projects
project_id(int)employee_id(int)
Identify the employee IDs that have more than 1 project.
这道题考察 SQL 的分组统计与 HAVING 过滤:需要从 employees_projects 关联表中按 employee_id 分组,统计每个员工对应的项目数量,并筛选出项目数大于 1 的员工 ID。关键点在于不要直接用 WHERE 过滤聚合结果,而应使用 GROUP BY + HAVING COUNT(*) > 1 来完成。
正文完