sql - Get data based on other row -


example

when row of id void, not show cc_type, need cc_type void rows.

case when cc_type = 'credit' or voided = 'yes' 'credit'      when cc_type = 'debit or voided = 'yes' 'debit' end 

obviously, approach wouldn't work. row 3 consider credit since satisfy condition voided = 'yes'.

my logic if id , name same append cc_type value voided row, don't know how work.

thanks

you can use window function:

select   id,   name,   max(cc_type) on (partition id, name) cc_type,   voided   yourtable 

Popular posts from this blog