У меня такой запрос:
select user_id,
case when event='Analysis'
and max(case when event='Strat' then max_time end) over(partition by user_id) >
max(case when event='Analysis' then max_time end) over(partition by user_id) then null
**when event like 'Premium:%' and exists max(select distinct event from sub where event='Complete') over(partition by user_id) then null**
else event end event
from (
select distinct user_id, event,
[*bunch of other columns*]
max(time) max_time
from table
[*bunch of joins and filters*]
group by 1,2
) sub
В строке с ** я пытаюсь добавить такой пункт: если event like 'Premium:%', но у пользователя есть event='Complete' (в любой момент), измените его на event is null.
Какие-либо предложения? Спасибо


вам нужно использовать условную сумму в оконной функции, разбивая ее по идентификатору пользователя:
case
when event like 'Premium:%'
and sum(case when event='Complete' then 1 else 0 end) over (partition by user_id)>0
then null
else event end