select
case
when x in (500,400) then 'в том числе'
when x in (500,400,101) then 'всего'
else '' end as "итог",
sum (y) as "сумма"
from public.table
group by
case
when x in (500,400) then 'в том числе'
when x in (500,400,101) then 'всего'
else '' end