Q&A about the site for people interested in all aspects of producing and consuming coffee
CREATE table #yourtable ([Id] int, [Value] int, [ColumnName] varchar(13)) ; INSERT INTO #yourtable ([Id], [Value], [ColumnName]) VALUES (1, 30, 'first'), (2, 1393, 'second'), (3, 2.25, 'third'), (4, 110, 'fourth') ; select first, second, third, fourth ,fourth-first as calculations from ( select value, columnname from #yourtable ) d pivot ( max(value) for columnname in (first, second, third, fourth ) ) piv;