Over (partition ...) Detailed usage

Source: Internet
Author: User

Common analysis functions are listed as follows:
PW "XG * j RJ. w0row_number () over (partition by... order ...)
H * V} I * z/_: skp0rank () over (partition by... order by...) cnoug blog homepage. Z &] Q/7yzc 'K
Dense_rank () over (partition by... order by...) cnoug blog homepage LZ] w9c0g, Y u * A] W
Count () over (partition by... order ...)
"Z + A" C * n-] uh0max () over (partition by... order by...) cnoug blog homepage * 'z # G/R? /Q [} J
Min () over (partition by... order by...) cnoug blog homepage U/h] O} v]
Sum () over (partition by... order ...)
[}! _ [M % Y yp0avg () over (partition by... order ...)
+ Lyntx5i5rbl l0first_value () over (partition by... order ...)
J * ou # F? V4l8w0last_value () over (partition by... order by...) cnoug blog homepage/IB, m6ae
Lag () over (partition by... order ...)
4f v2y1fbh3f0lead () over (partition by... order ...)

Example: cnoug blog homepage I a7xfi? O
14:33:29 SQL> select type, qty fromTest;
U6pd7r $ o u {a0type Qty
) U7h,] v6u0 --------------------
Qd7leub0ug! Dhq01 3
C $ v8o4p. z9ll8b5x $ o01 6cnoug blog homepage 5o1 'C j | (?
2 5cnoug blog homepage e7zw | (]'t
2 9cnoug blog homepage 2q & M l2e? 5A
2 7

14:33:36 SQL> select type, qty, to_char (row_number () over (partition by type order by qty) | '/' | to_char (count (*) over (partition by type) as cnt2 from test; cnoug blog homepage RA /~ & P3in
Type qty cnt2cnoug blog homepage e1t ?. SW] @ 7z
--------------------------------
Z. J "] q {(L01 3 1/2cnoug blog homepage Z P5j-Q4C !? E
1 6 2/2cnoug blog homepage 5 ?; X/c3bi AP * o
2 5 1/3cnoug blog homepage D j5s 'n4 {0l? P
2 7 2/3
S {ecdk # bjo02 9 3/3

 

SQL> select * from test;

Id MC
A $ FQ #''? R0 ------------------------------------------------------------
Qf5s) Ca 'p0112gp01 11111
) M "I irbs9l02 22222
$ {% IPE/M03 33333
9j-^ 4p-i & A & MPI. 'eu04 44444

SQL> cnoug blog homepage & X % B? J + F "DM | n
SQL> select T. ID, MC, to_char (B. Rn) | '/' | T. idcnoug blog homepage u6w: S) WEF + q. G: MB! Su
2 from test T, cnoug blog homepage XH ^ 'o * M5 '1co
3 (select rownum rn from (select max (to_number (ID) Mid from test) connect by rownum <= mid) B
% Cz ao o-f04 where B. Rn <= to_number (T. ID) cnoug blog home DGP, w4x/l9w
5 order by ID, 3cnoug blog homepage Z % m p. T, |
6/

Id Mc to_char (B. Rn) | '/' | T. idcnoug blog homepage 9z ~ ^ @ Ww3c * l. c
---------------------------------------------------------------------------------------------------------------
? T (rl5m3r i9fo "iw01 11111 1/1cnoug blog homepage ZZ/3q: H
2 22222 1/2cnoug blog homepage '? /R {# Q (xuo
2 22222 2/2cnoug blog homepage tn6s; m? MQ. c
3 33333 1/3cnoug blog homepage k 'o-m /!?; Ag7a9n + q
3 33333 2/3
! Ly: J/A + n03 33333 3/3
J3a o-'dt04 44444 1/4
O + F! @ S7 [aw d8c # D0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.