来自两个表的所有记录对oracle SQL

问题描述 投票:0回答:1

我需要找到两个表之间记录的所有唯一对(不是排列)。以下是AA_1的所有排列:

with a1
as(
select
'abc' as a,
1 as dummy
from dual

union all

select
'efg' as a
1 as dummy
from dual)

select
a1_1.a,
a1_2.a
from a1 a1_1
join a1 a1_2 on a1_1.dummy = a1_2.dummy
where a1_1.a != a1_2.a;

输出(带有上面的片段):

+-----+-----+
|  A  | A_1 |
+-----+-----+
| efg | abc |
| abc | efg |
+-----+-----+

所需的输出:

+-----+-----+
|  A  | A_1 |
+-----+-----+
| efg | abc |
+-----+-----+

是否有一种获取对(而不是上面的排列)的方法?

sql oracle permutation
1个回答
1
投票

我认为您只想要<

select a1_1.a, a1_2.a
from a1 a1_1 join
     a1 a1_2
     on a1_1.dummy = a1_2.dummy and
        a1_1.a < a1_2.a;
© www.soinside.com 2019 - 2024. All rights reserved.