Это можно сделать с помощью string_to_array()
и оператора ALL
:
case
when 'Initial' = ALL(string_to_array(statuses, ',')) then 'Initial'
when 'Completed' = ALL(string_to_array(statuses, ',')) then 'Completed'
else 'InProgress'
end status
Демонстрация на DB Fiddle :
with t as (
select 'Initial,Initial' statuses
union all select 'Completed,Completed'
union all select 'Initial,Completed,Other'
)
select
statuses,
case
when 'Initial' = ALL(string_to_array(statuses, ',')) then 'Initial'
when 'Completed' = ALL(string_to_array(statuses, ',')) then 'Completed'
else 'InProgress'
end status
from t
statuses | status
:---------------------- | :---------
Initial,Initial | Initial
Completed,Completed | Completed
Initial,Completed,Other | InProgress