[英]Aggregate Function Dense_rank within group
Using Oracle 12C Its Regarding Dense_Rank Within Group Aggregate function, this function takes two columns(salary,commission) existing in (emp)table and provide its rank. 使用Oracle 12C的 Group Aggregate函数中有关Dense_Rank的功能,该函数采用(emp)表中存在的两列(工资,佣金)并提供其排名。 The results are little confusing.
结果有点混乱。 Rank is showed even though the values are not in database.
即使值不在数据库中,也会显示排名。 There are two records with 3000.
有两个记录为3000。
Existing values in db for db中的现有值
sal, comm 萨尔,通讯
3000,NULL 3000,空
3000,50 (updated one of the comm value from NULL to 50 in EMP table) 3000,50(将EMP表中的comm值之一从NULL更新为50)
Non Existing values in db for db中不存在的值
sal, comm 萨尔,通讯
3000,0 3000,0
3000,100 3000,100
3000,500 3000,500
Is it giving possible ranks,if so then its giving same rank(3) for comm 100,500 and NULL. 它是否给出可能的等级,如果是,那么它给comm 100,500和NULL给出相同的rank(3)。 And equal rank(2) for comm 0 and 50.
通讯0和50等于等级(2)。
ORDER BY SAL DESC AND COMM ASC. 通过SAL DESC和COMM ASC订购。
select DENSE_rank (3000,null) within group(order by sal desc,comm ) DENSE_NULL,
DENSE_rank (3000,0) within group(order by sal desc,comm) DENSE_ZERO,
DENSE_rank (3000,50) within group(order by sal desc,comm) DENSE_50,
DENSE_rank (3000,100) within group(order by sal desc,comm) DENSE_100,
DENSE_rank (3000,500) within group(order by sal desc,comm) DENSE_500
from emp;
Order by sal desc and comm asc 由Sal desc和comm asc排序
Here 49 is given x rank 这里给定49 x等级
50 is given y rank y等级为50
51 and NULL are given z rank. 51和NULL被赋予z等级。
SELECT DENSE_RANK (3000,49) WITHIN GROUP(ORDER BY sal DESC,comm) DENSE_49,
DENSE_RANK (3000,50) WITHIN GROUP(ORDER BY sal DESC,comm) DENSE_50,
DENSE_RANK (3000,51) WITHIN GROUP(ORDER BY sal DESC,comm) DENSE_51,
DENSE_RANK (3000,null) WITHIN GROUP(ORDER BY sal DESC,comm) DENSE_NULL
FROM emp;
Order by sal desc and comm desc 由sal desc和comm desc排序
Here 49 is given x rank 这里给定49 x等级
50 and 51 is given y rank 50和51被赋予y等级
NULL is given z rank. NULL赋予z等级。
SELECT DENSE_RANK (3000,49) WITHIN GROUP(ORDER BY sal DESC,comm desc) DENSE_49,
DENSE_RANK (3000,50) WITHIN GROUP(ORDER BY sal DESC,comm desc) DENSE_50,
DENSE_RANK (3000,51) WITHIN GROUP(ORDER BY sal DESC,comm desc) DENSE_51,
DENSE_RANK (3000,null) WITHIN GROUP(ORDER BY sal DESC,comm desc) DENSE_NULL
FROM emp;
It must not be concluded that the expressions assign the same rank because each of your DENSE_RANK
should be considered in isolation. 不能断定这些表达式分配相同的等级,因为应该单独考虑每个
DENSE_RANK
。 So, 0 and 50 have same rank because when compared independently with the entries in the table, they both fall under the same rank . 因此,0和50具有相同的等级,因为当与表中的条目独立比较时,它们都属于同一等级 。
DENSE_NULL DENSE_ZERO DENSE_50 DENSE_100 DENSE_500
---------- ---------- ---------- ---------- ----------
63 63 63 63 63
In case, you want to consider multiple hypothetical values to determine rank of the consolidated values, do a UNION ALL
with existing entries of the main table. 如果要考虑多个假设值以确定合并值的等级,请对主表的现有条目执行
UNION ALL
。
with hypoth(sal,comm) AS
(
select 330,null from dual union all
select 3000,0 from dual union all
select 3000,50 from dual union all
select 3000,500 from dual
)
select DENSE_rank (3000,null) within group(order by sal desc,comm ) DENSE_NULL,
DENSE_rank (3000,0) within group(order by sal desc,comm) DENSE_ZERO,
DENSE_rank (3000,50) within group(order by sal desc,comm) DENSE_50,
DENSE_rank (3000,100) within group(order by sal desc,comm) DENSE_100,
DENSE_rank (3000,500) within group(order by sal desc,comm) DENSE_500
from ( select salary as sal,commission_pct as comm from employees
UNION ALL
select sal,comm from hypoth
);
Which gives 这使
DENSE_NULL DENSE_ZERO DENSE_50 DENSE_100 DENSE_500
---------- ---------- ---------- ---------- ----------
66 63 64 65 65
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.