oracle - Determine where condition based on column values -


i have requirement if getting data particular column not null, need fetch records corresponding source_type, else need fetch records based on other column. let's take example of below record

enter image description here

in above case grouping done based on column grp. in particular group, if source_type column not null of records, need fetch records group have same value in source column, source_type not null. in case expected output

enter image description here

but in case within group if source_type column null records, need fetch records group have same value in source column match_type='mp'.in case expected output

enter image description here

looks nice job analytical functions...

with xyz (     select x.*,         count(x.source_type) on (partition x.grp, x.source) non_null_source_type#,         first_value(case when x.match_type = 'mp' x.source end) on (partition x.grp) source_from_mp$     table x ) select * xyz non_null_source_type# > 0     or non_null_source_type# = 0         , source = source_from_mp$ ; 

... in case understood use case correctly.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -