简体   繁体   中英

count and display how many times data in SQL

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM