w*********n 发帖数: 439 | 1 Create the following reports for the HR department: Include the department
number, department name, and the number of employees working in each
department that:
• Has the highest number of employees
• Has the lowest number of employees | B*****g 发帖数: 34098 | 2 90%+数据库版sql问题可以用partition by解决
【在 w*********n 的大作中提到】 : Create the following reports for the HR department: Include the department : number, department name, and the number of employees working in each : department that: : • Has the highest number of employees : • Has the lowest number of employees
| l******b 发帖数: 39 | 3
如果你不想用partition by, 可以用子查询
SQL> with a1 as (
2 select department_id, count(*) as num_emp from employees group by
department_id),
3 a2 as (
4 select department_id, num_emp from a1 where num_emp in ((select max(
num_emp) from a1), (select min(num_emp) from a1) ))
5 select d.department_id, d.department_name, a2.num_emp from departments
d join a2 on d.department_id = a2.department_id ;
DEPARTMENT_ID DEPARTMENT_NAME NUM_EMP
------------- ------------------------------ ----------
10 Administration 1
40 Human Resources 1
50 Shipping 45
70 Public Relations 1
【在 w*********n 的大作中提到】 : Create the following reports for the HR department: Include the department : number, department name, and the number of employees working in each : department that: : • Has the highest number of employees : • Has the lowest number of employees
| h********o 发帖数: 2316 | 4 有人回答了问题,lz也不招呼一声,这个风气很不好 |
|