由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 新手学数据库一个简单题求助
相关主题
问一道sql的面试题啊 自己实在是没想出来请求SQL语句
怎么写这个Query,谢谢问个sql的问题吧,搞不出来了. (转载)
SQL question这个问题可以用SQL 实现吗?
问个基础的理论问题----数据库的基本差异数据库问题求解
【转载】大家来讨论To get the 2nd, 3rd, 4th largest value
请问T-SQL中Group By之后怎么找到特定的recordQuestion about SQL server lock
请教SQL server的一个programming的问题,谢谢新手问个简单的SELECT问题
[SQL求助] 取每个group的第一个record请教高手,包子谢
相关话题的讨论汇总
话题: department话题: emp话题: num话题: employees话题: number
进入Database版参与讨论
1 (共1页)
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也不招呼一声,这个风气很不好
1 (共1页)
进入Database版参与讨论
相关主题
请教高手,包子谢【转载】大家来讨论
partition 表请问T-SQL中Group By之后怎么找到特定的record
SQL Server stupid questions请教SQL server的一个programming的问题,谢谢
初级问题[SQL求助] 取每个group的第一个record
问一道sql的面试题啊 自己实在是没想出来请求SQL语句
怎么写这个Query,谢谢问个sql的问题吧,搞不出来了. (转载)
SQL question这个问题可以用SQL 实现吗?
问个基础的理论问题----数据库的基本差异数据库问题求解
相关话题的讨论汇总
话题: department话题: emp话题: num话题: employees话题: number