Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 基于单列的多透视 请考虑以下表格: Id Year Month Type Value IsUpdate --------------------------------------------------------- 1 2011 1 T1 1000 0 2 2012 1 T1 2000 0 3 2011 1 T2 5000 1 4 2012 1 T2 500 0 5 2011 1 T3 11000 1 6 2012 1 T3 800 1_Sql_Sql Server_Sql Server 2012_Pivot - Fatal编程技术网

Sql 基于单列的多透视 请考虑以下表格: Id Year Month Type Value IsUpdate --------------------------------------------------------- 1 2011 1 T1 1000 0 2 2012 1 T1 2000 0 3 2011 1 T2 5000 1 4 2012 1 T2 500 0 5 2011 1 T3 11000 1 6 2012 1 T3 800 1

Sql 基于单列的多透视 请考虑以下表格: Id Year Month Type Value IsUpdate --------------------------------------------------------- 1 2011 1 T1 1000 0 2 2012 1 T1 2000 0 3 2011 1 T2 5000 1 4 2012 1 T2 500 0 5 2011 1 T3 11000 1 6 2012 1 T3 800 1,sql,sql-server,sql-server-2012,pivot,Sql,Sql Server,Sql Server 2012,Pivot,我想创建以下结果: Year Month T1_Value T1_IsUpdate T2_Value T2_IsUpdate T3_Value T3_IsUpdate ---------------------------------------------------------------------------------------------- 2011 1 1000 0 5000

我想创建以下结果:

Year   Month    T1_Value    T1_IsUpdate     T2_Value    T2_IsUpdate     T3_Value    T3_IsUpdate
----------------------------------------------------------------------------------------------
2011     1       1000            0           5000            1           11000           1
2012     1       2000            0           500             0           800             1
是否可以使用
PIVOT


谢谢

这是使用动态交叉表完成的。供参考:

结果

Year        Month       T1_Value    T1_IsUpdate T2_Value    T2_IsUpdate T3_Value    T3_IsUpdate
----------- ----------- ----------- ----------- ----------- ----------- ----------- -----------
2011        1           1000        0           5000        1           11000       1
2012        1           2000        0           500         0           800         1

您可以使用动态轴心或动态交叉表来实现这一点。
Year        Month       T1_Value    T1_IsUpdate T2_Value    T2_IsUpdate T3_Value    T3_IsUpdate
----------- ----------- ----------- ----------- ----------- ----------- ----------- -----------
2011        1           1000        0           5000        1           11000       1
2012        1           2000        0           500         0           800         1