[英]I have table as shown below with source,Target and KMS columns and i need out based on KMS columns
I need the output based on KMS. 我需要基于KMS的输出。 Table data and expected output:
表数据和预期输出:
if KMS is same and source and Target is same(1st and 2nd record are same logically) then consider it as one record 如果KMS相同并且源和目标相同(第一条记录和第二条记录在逻辑上相同),则将其视为一条记录
If the KMS is same and source and Target is different consider it as different record(consider the last record it has same KMS as 1st record but it different record) 如果KMS相同且源和目标不同,则将其视为不同的记录(考虑最后一条记录,其KMS与第一条记录相同,但其记录不同)
If we consider consider each record as a pair and then sort and transpose the source and target accordingly, you should be able to pick out what records go together. 如果我们考虑将每条记录视为一对,然后对源和目标进行分类和转置,那么您应该能够挑选出哪些记录在一起。
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;
The solution does not work for NULLS. 该解决方案不适用于NULL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.