I want to select the data and added a new column called 'check' based on the following rules:
I have created code but very very slow, because this is a sample data, so just wondering could anyone help with it please? Thanks
case
when Master_Consumer is null then
case when Bill_group = 'Consumer'
then Consumer_scope
else '' -- ??
end
when
min(case when Master_Consumer = Consumer and Consumer_scope = 'Out of scope' then 1 end)
over (partition by Master_Consumer) = 1
or Product like '%For Dairy%'
then 'Out of scope'
else Consumer_scope -- ??
end