[英]SQL: How to create result as shown below
I facing issue with the below case: 我面临以下案件的问题:
I/P Table: I / P表:
Column_1 Column_2
A A
B B
C C
D D
Cross Join will give me the below result Cross Join会给我以下结果
Actual O/P Value:
AA
AB--This combinati
on is Repeated
AC
AD
BA--This combination is Repeated
BB
BC
BD
CA
CB
CC
CD
DA
DB
DC
DD
Expected OP: 预期OP:
AA
AB
AC
AD
BB
BC
BD
CC
CD
DD
I dont want the combinations to be repeated: Like AB and BA. 我不希望重复这些组合:像AB和BA一样。
添加一个额外条件,要求第二个值大于或等于第一个值:
.... WHERE (Column_2 >= Column_1)
select distinct least(column_1, column_2), greatest(column_1, column_2)
from ip_table
cross join ip_table
order by 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.