简体   繁体   English

SQL Server中的数据安排

[英]Data Arrangement in SQL Server

I have output from a SQL query in this format: 我以这种格式输出SQL查询:

在此输入图像描述

Now, I want my output to look like this instead: 现在,我希望我的输出看起来像这样:

在此输入图像描述

Please guide me on the best possible solution. 请指导我找到最好的解决方案。 Thanks! 谢谢!

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 ? delta / percent In any case, you can add the appropriate calculation. 无论如何,您可以添加适当的计算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM