ebs oracle 落伍了吗_OracleEbs开发心得

技术心得

一、

SQL

查询:

1

列出同部门中工资高于

1000

的员工数量超过

2

人的部门,显示部门名字、地区名称

.

查询语句如下:

select

distinct

dept.department_name,loc.city

from

employees emp,departments dept,locations loc

where

emp.department_id=dept.department_id

and

dept.location_id=loc.location_id

and

EXISTS

(

select

1

from

employees emp2

where

emp2.department_id=emp.department_id

and

emp2.salary>

1000

group

by

emp2.department_id

having

count

(emp2.department_id)>

2

)

通常我们只需要对记录逐行的筛选,对于分组数据我们只能使用分组语句

avg

max

,

也就是说如果你想在

select

中得到这个属性那么“它们“也必须出现在

group

by

中或者你只想得到一个统计数据

.

回顾上面的例子

,

我们也可以用以下语句完成

:

select

dept.department_name,loc.city,

count

(*)

from

employees emp,departments dept,locations loc

where

emp.department_id=dept.department_id

and

dept.location_id=loc.location_id

and

emp.salary>

1000

group

by

dept.department_name,loc.city

having

count

(*) >

2

对于

group by

来说每一条

emp.department_id

必对应唯一

dept.department_id

dept.department_name

因此不论

group by department_id

还是

group by department_name,loc.city

达到的效果是一样的

2

、用一条语句查询出

scott.emp

表中每个部门工资前三位的数据

:

select department_id,max(salary) max_salary,max(decode (rank,2,salary,salary))mid_salary,min(salary) min_salary

from

(

select department_id,salary,rank from

(select emp.department_id,emp.employee_id,emp.salary,row_number()over(partition by emp.department_id order by emp.salary)

as rank

from employees emp) E

where E.rank<=3

)

group by department_id

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值