Použijte podmíněnou agregaci:
select sum(case when type = 1 then value else - value end) as value
from table t
group by year;
Použijte podmíněnou agregaci:
select sum(case when type = 1 then value else - value end) as value
from table t
group by year;