Home > database >  Oracle advanced query
Oracle advanced query

Time:09-21

Under such as dual query results for
SQL: select * from dual;
Result:
C1 count
A 2
3 b

Requirements: according to the count number, query the table multiple duplicate data, such as a column count for 2 found out record for 2 records, b is 3 duplicate records, then the result set is
A 2
A 2
3 b
3 b
3 b

Pray god help



CodePudding user response:

Someone!!!!!!

CodePudding user response:

 
SQL>
SQL> Create table test (c1 varchar (10), c int);
The Table created
SQL> The begin
2 insert into the test values (' a ', 2);
3 the insert into the test values (' b ', 3);
4 the end;
5/
PL/SQL procedure successfully completed
SQL> The select c1, c
2 the from test
3 connect by level & lt;=c
4 and the prior c1=c1
5 and the prior dbms_random. The value is not null;
C1 C
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
A 2
A 2
3 b
3 b
3 b
SQL> Drop table test purge;
Table dropped

SQL>

CodePudding user response:

SQL: select * from dual;
Result:
C1 count
A 2
3 b

This is not possible,

CodePudding user response:

 
With TMP as
(
Select the 'a' as c1, c2 from 2 dual
Union all
Select 'b' as c1 and c2 from 3 dual
)
Select c1 and c2
The from TMP
Connect by the prior c2=c2
And level & lt;=c2
And the prior dbms_random. The value is not null;

CodePudding user response:

The query SELECT

http://www.verejava.com/? Id=17173779389953

CodePudding user response:

# 6, pay attention to the topic!

CodePudding user response:

 with a as (select the 'a' c1, 2 count from dual 
Union all
Select 'b', 3 from dual)
Select * from aa connect by the prior c1=c1 and the prior dbms_random. The value is not null and level<=
Count

1 a 2
2 a, 2
3 b 3
4 b 3
5 b 3
A statement out, if you want to understand, to study the PRIOR ROWID=ROWID
  • Related