NTILE

NTILE(expr) OVER ([ query_partition_clause ] order_by_clause)

SELECT DEPARTMENT_ID,
       LAST_NAME,
       SALARY,
       NTILE(5) OVER(PARTITION BY DEPARTMENT_ID ORDER BY SALARY DESC) AS QUARTILE
  FROM EMPLOYEES
 WHERE DEPARTMENT_ID IN (80, 100)
 ORDER BY DEPARTMENT_ID DESC, QUARTILE, LAST_NAME, SALARY;

DEPARTMENT_ID LAST_NAME          SALARY   QUARTILE
------------- ------------------------- ---------- ----------
          100 Faviet                         9000.00          1
          100 Greenberg                   12008.00          1
          100 Chen                           8200.00          2
          100 Urman                         7800.00          3
          100 Sciarra                        7700.00          4
          100 Popp                           6900.00          5
           80 Abel                            11000.00          1
           80 Cambrault                   11000.00          1
           80 Errazuriz                     12000.00          1
           80 Ozer                           11500.00          1
           80 Partners                     13500.00          1
           80 Russell                       14000.00          1
           80 Zlotkey                      10500.00          1
           80 Bernstein                     9500.00          2
           80 Bloom                        10000.00          2
           80 Fox                             9600.00          2
           80 King                          10000.00          2
           80 Sully                          9500.00          2
           80 Tucker                      10000.00          2
           80 Vishney                     10500.00          2
           80 Greene                       9500.00          3
           80 Hall                         9000.00          3
           80 Hutton                       8800.00          3
           80 Livingston                   8400.00          3
           80 McEwen                       9000.00          3
           80 Smith                        8000.00          3
           80 Taylor                       8600.00          3
           80 Bates                        7300.00          4
           80 Cambrault                    7500.00          4
           80 Doran                        7500.00          4
           80 Marvins                      7200.00          4
           80 Olsen                        8000.00          4
           80 Sewall                       7000.00          4
           80 Smith                        7400.00          4
           80 Ande                         6400.00          5
           80 Banda                        6200.00          5
           80 Johnson                      6200.00          5
           80 Kumar                        6100.00          5
           80 Lee                          6800.00          5
           80 Tuvault                      7000.00          5

posted @ 2014-12-20 23:01  智能先行者  阅读(293)  评论(0编辑  收藏  举报