栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Oracle/PLSQL: Cume

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Oracle/PLSQL: Cume

In Oracle/PLSQL, the cume_dist function returns the cumulative distribution of a value in a group of values. The cume_dist function will return a value that is >0 and <=1.

The cume_dist function can be used two ways - as an Aggregate function or as an Analytic function.

Syntax #1 - Used as an Aggregate Function

As an Aggregate function, the cume_dist returns the relative position of a row within a group of rows.

The syntax for the cume_dist function when used as an Aggregate function is:

cume_dist( expression1, ... expression_n ) WITHIN GROUP ( ORDER BY expression1, ... expression_n )

expression1 .. expression_n can be one or more expressions which identify a unique row in the group.

Note

There must be the same number of expressions in the first expression list as there is in the ORDER BY clause.

The expression lists match by position so the data types must be compatible between the expressions in the first expression list as in the ORDER BY clause.

Applies To

  • Oracle 11g, Oracle 10g, Oracle 9i

For Example

select cume_dist(1000, 500) WITHIN GROUP (ORDER BY salary, bonus)

from employees;

The SQL statement above would return the cumulative distribution of an employee with a salary of $1,000 and a bonus of $500 from within the employees table.

Syntax #2 - Used as an Analytic Function

As an Analytic function, the cume_dist returns the relative position of a value within a group of values.

The syntax for the cume_dist function when used as an Analytic function is:

cume_dist() OVER ( [ query_partition_clause] ORDER BY clause )

Applies To

  • Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i

For Example

select employee_name, salary,

cume_dist() OVER (PARTITION BY department ORDER BY salary)

from employees

where department = 'Marketing';

The SQL statement above would return the salary percentile for each employee in the Marketing department.

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1006657.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号