Solutionunvalidated
You need to use an aggregated function e.g. `max` to check the tomato — select r.product_group_id, r.group_name, r.class, case when max(case when r.name ='tomato' then r.name end) = 'tomato' then 'invalid' else 'valid' end label. Tension: not group by on the `label`. Outcome: group by r.product_group_id, r.group_name, r.class.
43a0f75d-c3fa-479a-bc75-8432d247123f
You need to use an aggregated function e.g. max to check the tomato — select r.product_group_id, r.group_name, r.class, case when max(case when r.name ='tomato' then r.name end) = 'tomato' then 'invalid' else 'valid' end label. Tension: not group by on the label. Outcome: group by r.product_group_id, r.group_name, r.class.