Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.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 server 对数据透视表中的数据进行排序_Sql Server_Sorting_Pivot Table - Fatal编程技术网

Sql server 对数据透视表中的数据进行排序

Sql server 对数据透视表中的数据进行排序,sql-server,sorting,pivot-table,Sql Server,Sorting,Pivot Table,我有一个结构如下的表格: Title text LineNo integer Key text Value text 我创建了一个透视表,用于将行数据转换为列名: SELECT * FROM (SELECT Title, [Key],[Value] FROM Table1 WHERE [Key] LIKE 'Field_%' AND [LineNo]>0) as Data PIVOT( MAX([Value]) FOR [Key] IN([Field_1],[Field_2],[F

我有一个结构如下的表格:

Title text
LineNo integer
Key   text
Value text
我创建了一个透视表,用于将行数据转换为列名:

SELECT * FROM
(SELECT Title, [Key],[Value] FROM Table1 WHERE [Key] LIKE 'Field_%' AND [LineNo]>0) as Data 
PIVOT(
MAX([Value])
FOR [Key] IN([Field_1],[Field_2],[Field_3])) As Piv

现在,我如何按标题和行号对数据进行排序?

pivot
转换为
dynamic pivot
,然后在生成pivot列列表时按所需顺序对列进行排序您的结果有4列,标题、字段_1、字段_2、字段_3,对吗?NoDisplayName,事实证明,创建动态数据透视查询是不必要的——我只是在数据透视表别名之后添加了ORDER BY