分析函数-DENSE_RANK

Analytic Syntax(分析语法)

Aggregate Syntax(聚集语法)

Purpose

DENSE_RANK computes the rank of a row in an ordered group of rows and returns the rank as a NUMBER. The ranks are consecutive(连续的) integers beginning with 1. The largest rank value is the number of unique values returned by the query. Rank values are not skipped in the event of ties(结). Rows with equal values for the ranking criteria(条件) receive the same rank. This function is useful for top-N and bottom-N reporting.

This function accepts as arguments any numeric datatype and returns NUMBER.

  • As an aggregate function, DENSE_RANK calculates the dense(密集的) rank of a hypothetical(假设的) row identified by the arguments of the function with respect to a given sort specification(规格). The arguments of the function must all evaluate to constant expressions within each aggregate group, because they identify a single row within each group. The constant argument expressions and the expressions in the order_by_clause of the aggregate match by position. Therefore, the number of arguments must be the same and types must be compatible.

  • As an analytic function, DENSE_RANK computes the rank of each row returned from a query with respect to the other rows, based on the values of the value_exprs in the order_by_clause.

Analytic Example

返回各部门工资排名前三位的员工(6.5)

SELECT deptno,ename,sal FROM(
    SELECT deptno,ename,sal,
    DENSE_RANK() OVER(PARTITION BY deptno ORDER BY sal DESC) AS dense_rank -- DENSE_rank分析函数,PARTITION分组子句
    FROM scott.emp ORDER BY 1,3 DESC
) WHERE dense_rank<=3;
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值