Проверка ваших данных: http://demo.gethue.com/hue/editor?editor=293916
with your_table as -------use your table instead of this subquery
(
select stack(6,
1 ,'A', 'y','n', '2009/01/01',
1 ,'B', 'n','y', '2019/02/09',
1 ,'C', null,'' , '2018/05/07',
2 ,'A', null,'y', '2005/02/02',
2 ,'B', null,'y', '2006/05/05',
2 ,'C', 'n', null, '2018/01/01'
) as (Ik, priority, ind1, ind2, date)
) -------use your table instead of this subquery
select ik,
max(case when priority ='A' and ind1='y' then 'y' else last_ind1 end) ind1,
max(case when priority ='A' and ind2='y' then 'y' else last_ind2 end) ind2
from
(
select Ik, priority, ind1, ind2, date,
last_value(ind1) over (partition by Ik order by date) last_ind1,
last_value(ind2) over (partition by Ik order by date) last_ind2
from your_table -------use your table instead
)s
group by ik;
Результат:
ik ind1 ind2
1 y y
2 n y