sql - Conditional Self Joins -
suppose have data in table :
trade id | source ----------------- x | lch x | commodore y | lch z | commodore
i output :
x | lch y | lch z | commodore
meaning if there "lch" entry given trade id, take precedence.
i have done in java or other programming language getting basic results after joining tables , filter using map etc. due performance reasons using query @ first place.
could please have , let me know if there solution in sql.
this task windowed aggregate function, no need join:
select trade_id, source ( select trade_id, source, row_number() on (partition trade_id oder case when source = 'lch' 0 else 1 end) rn your_table ) dt rn = 1
Comments
Post a Comment