日期:2014-05-16  浏览次数:20713 次

求一个单句SQL...
我有一张表T_A
数据形如:

col_a col_b
AAA 2
BBB 3
CCC 5

如何写一个单句SQL,得到下面的数据:

AAA 1
AAA 2
BBB 1
BBB 2
BBB 3
CCC 1
CCC 2
CCC 3
CCC 4
CCC 5

谢谢!

------解决方案--------------------
SQL code

create table t1 (c1 varchar2(10),c2 number(5));

insert into t1 values ('aaa',2);
insert into t1 values ('bbb',3);
insert into t1 values ('ccc',5);
commit;


select distinct c1,level c2
from t1
connect by level <= c2
order by c1


     c1    c2
---------------------
1    aaa    1
2    aaa    2
3    bbb    1
4    bbb    2
5    bbb    3
6    ccc    1
7    ccc    2
8    ccc    3
9    ccc    4
10    ccc    5