sql - Query to filter records based on specific conditions -


there table a_status_check following data:

enter image description here

the requirement is: if status lc , both present, consider lc. otherwise, consider be. ignore other codes id.

so, result should like:

enter image description here

i tried decode , case functions no luck. can please help.

use analytical functions:

select distinct   id,   first_value (status) on (partition id order status desc) status,   first_value (amt   ) on (partition id order status desc) amt   tq84_a_status_check   status in ('lc', 'be') order   id; 

testdata:

create table tq84_a_status_check (   id number,   status varchar2(10),   amt number );  select distinct   id,   first_value (status) on (partition id order status desc) status,   first_value (amt   ) on (partition id order status desc) amt   tq84_a_status_check   status in ('lc', 'be') order   id; 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -