oracle分析函数(3)

1. ntile

--ntile
select e.employee_id,
       e.last_name,
       e.salary,
       e.department_id,
       ntile(10) over(order by e.salary desc) bucket --根据工资排序后,员工分配到10个组里,可以理解为工资相近的会被分配到相同的bucket
  from employees e;

 

2.percentile_cont,percentile_disc

--percentile_cont(P) 如果共有N行数据,及RN = (1 + P * (N - 1)),CRN = CEILING(RN), FRN = FLOOR(RN)
/*If (CRN = FRN = RN) then the result is
  (value of expression from row at RN)
Otherwise the result is
  (CRN - RN) * (value of expression for row at FRN) +
  (RN - FRN) * (value of expression for row at CRN)*/
--percontile_disc(0.5) 如果cume_dist计算的结果中有等于0.5的返回,如果没有取比0.5大的最小的一个值
--作为聚合函数
select e.department_id,
       percentile_cont(0.5) within group(order by e.salary),
       percentile_disc(0.5) within group(order by e.salary)
  from employees e
 group by e.department_id;

select e.employee_id,
       e.last_name,
       e.salary,
       e.department_id,
       percentile_cont(0.5) within group(order by e.salary) over(partition by e.department_id),
       percent_rank() over(partition by e.department_id order by e.salary)
  from employees e;

select e.employee_id,
       e.last_name,
       e.salary,
       e.department_id,
       percentile_disc(0.5) within group(order by e.salary) over(partition by e.department_id),
       cume_dist() over(partition by e.department_id order by e.salary)
  from employees e;

 

3. ratio_to_report

select e.employee_id,
       e.last_name,
       e.department_id,
       e.salary,
       ratio_to_report(e.salary) over(partition by e.department_id) --查询每个人的工资在部门内的占比
  from employees e
 order by e.department_id;

 

转载于:https://www.cnblogs.com/yasun/p/5178998.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值