SQL Distinct Pair Groupings -
i interested in manipulating data so:
my source data:
from | | rate ---------------- eur | aud | 1.5895 eur | bgn | 1.9558 eur | gbp | 0.7347 eur | usd | 1.1151 gbp | aud | 2.1633 gbp | bgn | 2.6618 gbp | eur | 1.3610 gbp | usd | 1.5176 usd | aud | 1.4254 usd | bgn | 1.7539 usd | eur | 0.8967 usd | gbp | 0.6589
in regards "distinct pairs", consider following "duplicates".
eur | usd matches usd | eur eur | gbp matches gbp | eur gbp | usd matches usd | gbp
i want source data filtered such removes 1 of above "duplicates", such final table 3 records less original. not care record "duplicates" kept or removed, long 1 selected.
i have tried many variations of joins, exists, except, distinct, group by, logical comparisons (< >) , feel close given approach... not seem click.
my favorite effort has involved inner joining on except:
select a.[from], a.[to], a.[rate] table inner join ( select distinct [from], [to] table except ( select [to] [from], [from] [to] table ) ) b on a.[from] = b.[from] , a.[to] = b.[to]
but alas, removes of matched pairs.
i can suggest easy, if doesn't matter 1 of want, can pick 1 rate bigger 1 or on contrary 1 smaller. each pare should 1 rate bigger , 1 smaller (make sense)
select * table rate>1
Comments
Post a Comment