我需要基于KMS的输出。表数据和预期产出:
答案 0 :(得分:0)
如果我们考虑将每条记录视为一对,然后相应地对源和目标进行排序和转置,那么您应该能够找出哪些记录在一起。
with data_from_vijay as(
select 'Bijapur' as source, 'Bangalore' as target, 500 as kms from dual union all
select 'Bangalore' as source, 'Bijapur' as target, 500 as kms from dual union all
select 'Pune' as source, 'Bangalore' as target, 700 as kms from dual union all
select 'Bangalore' as source, 'Pune' as target, 700 as kms from dual union all
select 'Mangalore' as source, 'Bangalore' as target, 400 as kms from dual union all
select 'Bangalore' as source, 'Belgaum' as target, 500 as kms from dual
)
select distinct
least(source, target) as source
,greatest(source, target) as target
,kms
from data_from_vijay;
该解决方案不适用于NULLS。