如何按顺序生成重复数字
How to generate repeating numbers in sequence
我想生成这个序列
col sequence
01 01
01 02
01 03
01 04
01 05
02 01
02 02
02 03
02 04
02 05
..
..
12 01
12 02
12 03
12 04
12 04
并将此作为序列添加到另一个 select。
你想要 row_numner()
:
select col, row_number() over (partition by col order by col) as sequence
from table t;
您可以使用子查询进行进一步的操作。
分层查询可能有助于生成您发布的结果:
SQL> with
2 c1 as
3 (select lpad(1 + level - 1, 2, '0') col1
4 from dual
5 connect by level <= 12
6 ),
7 c2 as
8 (select lpad(1 + level - 1, 2, '0') col2
9 from dual
10 connect by level <= 5
11 )
12 select c1.col1, c2.col2
13 from c1 cross join c2
14 order by c1.col1, c2.col2;
CO CO
-- --
01 01
01 02
01 03
01 04
01 05
02 01
02 02
02 03
02 04
02 05
03 01
03 02
<snip>
11 04
11 05
12 01
12 02
12 03
12 04
12 05
60 rows selected.
SQL>
我想生成这个序列
col sequence
01 01
01 02
01 03
01 04
01 05
02 01
02 02
02 03
02 04
02 05
..
..
12 01
12 02
12 03
12 04
12 04
并将此作为序列添加到另一个 select。
你想要 row_numner()
:
select col, row_number() over (partition by col order by col) as sequence
from table t;
您可以使用子查询进行进一步的操作。
分层查询可能有助于生成您发布的结果:
SQL> with
2 c1 as
3 (select lpad(1 + level - 1, 2, '0') col1
4 from dual
5 connect by level <= 12
6 ),
7 c2 as
8 (select lpad(1 + level - 1, 2, '0') col2
9 from dual
10 connect by level <= 5
11 )
12 select c1.col1, c2.col2
13 from c1 cross join c2
14 order by c1.col1, c2.col2;
CO CO
-- --
01 01
01 02
01 03
01 04
01 05
02 01
02 02
02 03
02 04
02 05
03 01
03 02
<snip>
11 04
11 05
12 01
12 02
12 03
12 04
12 05
60 rows selected.
SQL>