count and display how many times data in SQL

时间:2017-08-05 12:15:27

标签: sql oracle oracle10g

I have one table like.count and display how many times data

SQL> select * from COUNT_TEST;

NAME                 ID
-------------------- ---------
A                    4
B                    3
C                    2
D                    1

I want output like this:

name     id
A        4
A        4
A        4
A        4
B        3
B        3
B        3
C        2
C        2
D        1

Thanks in advance.

1 个答案:

答案 0 :(得分:2)

with COUNT_TEST(NAME, ID) as(
 select 'A',4 from DUAL union all
 select 'B',3 from DUAL union all
 select 'C',2 from DUAL union all
 select 'D',1 from DUAL
)
  select NAME, ID
    from COUNT_TEST
 connect by NAME=prior NAME and level<=ID
     and prior DBMS_RANDOM.value is not null;

Here is a Rextester for it.