Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.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 如何取消PIVOT以将列拆分为行?_Sql_Sql Server - Fatal编程技术网

Sql 如何取消PIVOT以将列拆分为行?

Sql 如何取消PIVOT以将列拆分为行?,sql,sql-server,Sql,Sql Server,我有一个sql查询(使用MS-sql 2005)生成具有以下列的数据: TimeStamp | SpeedMax | SpeedMin | HeightMax | HeightMin ------------------------------------------------------- 10 | 50 | 10 | 300 | 70 我需要的表格是: TimeStamp | Speed | Height ----------------

我有一个sql查询(使用MS-sql 2005)生成具有以下列的数据:

TimeStamp | SpeedMax | SpeedMin | HeightMax | HeightMin
-------------------------------------------------------
10        | 50       | 10       | 300       | 70
我需要的表格是:

TimeStamp | Speed | Height
---------------------------
10        | 50    | 300          <-- one row for the max values 
10        | 10    | 70           <-- a second row for the min values
时间戳|速度|高度
---------------------------
10        | 50    | 300          
你可以加上

OPTION (FORCE ORDER)
避免对
表进行双重扫描

你可以加上

OPTION (FORCE ORDER)
要避免对
表进行双重扫描,请尝试

SELECT TimeStamp, SpeedMax AS Speed, HeightMax AS Height
FROM Table
UNION ALL
SELECT TimeStamp, SpeedMin AS Speed, HeightMin AS Height
FROM Table
试一试