0nir
0nir

Reputation: 1355

Data Arrangement in SQL Server

I have output from a SQL query in this format:

enter image description here

Now, I want my output to look like this instead:

enter image description here

Please guide me on the best possible solution. Thanks!

Upvotes: 1

Views: 191

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269763

I would do this as:

select v.*
from t cross apply
     (values ('2012-2013', t.Delta2012_2013, t.Percent2012_2013),
             ('2012-2014', t.Delta2012_2014, t.Percent2012_2014)
     ) v(row, delta, percent);

It is unclear how to calculate the total. Is it a constant? Is it delta / percent ? In any case, you can add the appropriate calculation.

Upvotes: 3

Related Questions