Home > database >  Group number
Group number

Time:09-21

Such as table A:
A. A
A, b
A c
A, B
B B
For two group Numbers at the same time, get the following:
A. A 1 1
A, 1 b, 2
A 3 c 1
A, 2 B 1
B 2, 3, B
Excuse me, ladies and gentlemen, in the select * from (.. Nested), the SQL what to write?

CodePudding user response:

Dense_rank () over (order by a1),
Rank () over (partition by a1 order by a2)

CodePudding user response:

Describe the planning is clear,

CodePudding user response:

Try the following solutions:
 
The create table TMP as
Select the 'A' as c1, 'A' as c2 from dual union all
Select the 'A' as c1, 'b' as c2 from dual union all
Select the 'A' as c1, 'c' as c2 from dual union all
Select 'B' as c1, 'a' as c2 from dual union all
Select 'B' as c1, 'B' as c2 from dual

Select c1 and c2, dense_rank () over (order by c1) as Dr, rank () over (partition by c1 order by c2) as fairly rk from TMP.
  • Related