<i id='mrCrz'><tr id='mrCrz'><dt id='mrCrz'><q id='mrCrz'><span id='mrCrz'><b id='mrCrz'><form id='mrCrz'><ins id='mrCrz'></ins><ul id='mrCrz'></ul><sub id='mrCrz'></sub></form><legend id='mrCrz'></legend><bdo id='mrCrz'><pre id='mrCrz'><center id='mrCrz'></center></pre></bdo></b><th id='mrCrz'></th></span></q></dt></tr></i><div id='mrCrz'><tfoot id='mrCrz'></tfoot><dl id='mrCrz'><fieldset id='mrCrz'></fieldset></dl></div>

<small id='mrCrz'></small><noframes id='mrCrz'>

    <bdo id='mrCrz'></bdo><ul id='mrCrz'></ul>

  • <tfoot id='mrCrz'></tfoot>
        <legend id='mrCrz'><style id='mrCrz'><dir id='mrCrz'><q id='mrCrz'></q></dir></style></legend>
      1. oracle 中的 RANK() 和 DENSE_RANK() 函数有什么区别?

        时间:2023-09-19

        <legend id='Wa3EA'><style id='Wa3EA'><dir id='Wa3EA'><q id='Wa3EA'></q></dir></style></legend>

        <small id='Wa3EA'></small><noframes id='Wa3EA'>

            <tfoot id='Wa3EA'></tfoot>

                <bdo id='Wa3EA'></bdo><ul id='Wa3EA'></ul>
                    <tbody id='Wa3EA'></tbody>

                • <i id='Wa3EA'><tr id='Wa3EA'><dt id='Wa3EA'><q id='Wa3EA'><span id='Wa3EA'><b id='Wa3EA'><form id='Wa3EA'><ins id='Wa3EA'></ins><ul id='Wa3EA'></ul><sub id='Wa3EA'></sub></form><legend id='Wa3EA'></legend><bdo id='Wa3EA'><pre id='Wa3EA'><center id='Wa3EA'></center></pre></bdo></b><th id='Wa3EA'></th></span></q></dt></tr></i><div id='Wa3EA'><tfoot id='Wa3EA'></tfoot><dl id='Wa3EA'><fieldset id='Wa3EA'></fieldset></dl></div>

                • 本文介绍了oracle 中的 RANK() 和 DENSE_RANK() 函数有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  RANK()DENSE_RANK() 函数有什么区别?如何在下面的emptbl表中找出第n个薪水?

                  What's the difference between RANK() and DENSE_RANK() functions? How to find out nth salary in the following emptbl table?

                  DEPTNO  EMPNAME    SAL
                  ------------------------------
                  10       rrr    10000.00
                  11       nnn    20000.00
                  11       mmm    5000.00
                  12       kkk    30000.00
                  10       fff    40000.00
                  10       ddd    40000.00
                  10       bbb    50000.00
                  10       ccc    50000.00
                  

                  如果表数据中有nulls,如果我想找出nth的salary怎么办?

                  If in the table data having nulls, what will happen if I want to find out nth salary?

                  推荐答案

                  RANK 为您提供有序分区内的排名.平局被分配相同的排名,跳过下一个排名.因此,如果您有 3 个项目处于第 2 位,则列出的下一个排名将是第 5 位.

                  RANK gives you the ranking within your ordered partition. Ties are assigned the same rank, with the next ranking(s) skipped. So, if you have 3 items at rank 2, the next rank listed would be ranked 5.

                  DENSE_RANK 再次为您提供有序分区内的排名,但排名是连续的.如果有多个项目的等级,则不跳过等级.

                  DENSE_RANK again gives you the ranking within your ordered partition, but the ranks are consecutive. No ranks are skipped if there are ranks with multiple items.

                  至于空值,它取决于 ORDER BY 子句.这是一个简单的测试脚本,您可以使用它来查看会发生什么:

                  As for nulls, it depends on the ORDER BY clause. Here is a simple test script you can play with to see what happens:

                  with q as (
                  select 10 deptno, 'rrr' empname, 10000.00 sal from dual union all
                  select 11, 'nnn', 20000.00 from dual union all
                  select 11, 'mmm', 5000.00 from dual union all
                  select 12, 'kkk', 30000 from dual union all
                  select 10, 'fff', 40000 from dual union all
                  select 10, 'ddd', 40000 from dual union all
                  select 10, 'bbb', 50000 from dual union all
                  select 10, 'xxx', null from dual union all
                  select 10, 'ccc', 50000 from dual)
                  select empname, deptno, sal
                       , rank() over (partition by deptno order by sal nulls first) r
                       , dense_rank() over (partition by deptno order by sal nulls first) dr1
                       , dense_rank() over (partition by deptno order by sal nulls last) dr2
                   from q; 
                  
                  EMP     DEPTNO        SAL          R        DR1        DR2
                  --- ---------- ---------- ---------- ---------- ----------
                  xxx         10                     1          1          4
                  rrr         10      10000          2          2          1
                  fff         10      40000          3          3          2
                  ddd         10      40000          3          3          2
                  ccc         10      50000          5          4          3
                  bbb         10      50000          5          4          3
                  mmm         11       5000          1          1          1
                  nnn         11      20000          2          2          2
                  kkk         12      30000          1          1          1
                  
                  9 rows selected.
                  

                  这是一个链接 一个很好的解释和一些例子.

                  Here's a link to a good explanation and some examples.

                  这篇关于oracle 中的 RANK() 和 DENSE_RANK() 函数有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何将日志表中的数据导出到oracle中的电子邮件正文 下一篇:ORA-00054: 资源繁忙并获取指定的 NOWAIT 或超时过期

                  相关文章

                    <legend id='IMkyj'><style id='IMkyj'><dir id='IMkyj'><q id='IMkyj'></q></dir></style></legend>
                      <bdo id='IMkyj'></bdo><ul id='IMkyj'></ul>

                      <tfoot id='IMkyj'></tfoot>

                      <small id='IMkyj'></small><noframes id='IMkyj'>

                      <i id='IMkyj'><tr id='IMkyj'><dt id='IMkyj'><q id='IMkyj'><span id='IMkyj'><b id='IMkyj'><form id='IMkyj'><ins id='IMkyj'></ins><ul id='IMkyj'></ul><sub id='IMkyj'></sub></form><legend id='IMkyj'></legend><bdo id='IMkyj'><pre id='IMkyj'><center id='IMkyj'></center></pre></bdo></b><th id='IMkyj'></th></span></q></dt></tr></i><div id='IMkyj'><tfoot id='IMkyj'></tfoot><dl id='IMkyj'><fieldset id='IMkyj'></fieldset></dl></div>