sql - Query to filter records based on specific conditions -
there table a_status_check following data:

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

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
Post a Comment