CodePudding user response:
After another wall bumps bumpsCodePudding user response:
- test data
The create table t1 (c1 varchar2 (10), c2 varchar2 (10))
Insert into t1 values (' A ', 'B');
Insert into t1 values (' A ', 'B');
Insert into t1 values (' A ', 'B');
Insert into t1 values (' A ', 'B');
Insert into t1 values (' B ', 'A');
Insert into t1 values (' B ', 'A');
Insert into t1 values (' B ', 'A');
- query record
Select count (*)
The from t1
Where the exists (select * from t1 to t2 where t1. The c1=t2. C2 and t1. The c2=t2. The c1)
CodePudding user response:
SQL implementation is as follows:
Select c1 and c2, count (*)
The from (select cardno1 as c1, cardno2 as c2 from trans
Union all
The select cardno2, cardno1 from trans
)
Group by c1 and c2
Having the count (*) & gt; 10;
CodePudding user response:
The original poster is want to each other have a transfer? Not more than 11 times should be turning a single?With c as (select cardno1 cardno2, count (1) the from CNT trans group by cardno1, cardno2)
Select c1 cardno1, c1 cardno2, c1. The CNT + c2. The CNT CNT
The from c c1, c2 c
Where c1. Cardno1=c2. Cardno2
And c1. Cardno2=c2. Cardno1
And c1. CNT + c2. CNT & gt; 10;
Should be more appropriate
CodePudding user response:
With c as (select cardno1 cardno2, count (1) the from CNT trans group by cardno1, cardno2)Select c1 cardno1, c1 cardno2, c1. The CNT + c2. The CNT CNT
The from c c1, c2 c
Where c1. Cardno1=c2. Cardno2
And c1. Cardno2=c2. Cardno1
And c1. CNT + c2. CNT & gt; 10;
This was a little problem, turn to include and transferred
CodePudding user response:
Wrong, two-thirds of the floor to the right, you look at the performance comparison is excellent!CodePudding user response:
Select the flag, the count (*)
The from (select c1,
C2,
(case
The when c1 & gt; C2 then
C1
The else
C2
End) | | ', '| | (case
The when c1 & gt; C2 then
C2
The else
C1
End) flag
The from t1 v1
a)Group by flag
Having the count (*) & gt;=5
CodePudding user response:
Select the flag, the count (*)The from (select c1,
C2,
(case
The when c1 & gt; C2 then
C1 | | ', '| | c2
The else
C2 | | ', '| | c1
End) flag
The from t1 v1
a)Group by flag
Having the count (*) & gt;=5
CodePudding user response: