sql 2005 行列转换
2010-01-20 12:45
405 查看
将列值转为行
将行转为列
SELECT 'AverageCost' AS Cost_Sorted_By_Production_Days, [0], [1], [2], [3], [4] FROM (SELECT DaysToManufacture, StandardCost FROM Production.Product) AS SourceTable PIVOT ( AVG(StandardCost) FOR DaysToManufacture IN ([0], [1], [2], [3], [4]) ) AS PivotTable;
将行转为列
--Create the table and insert values as portrayed in the previous example. CREATE TABLE pvt (VendorID int, Emp1 int, Emp2 int, Emp3 int, Emp4 int, Emp5 int); GO INSERT INTO pvt VALUES (1,4,3,5,4,4); INSERT INTO pvt VALUES (2,4,1,5,5,5); INSERT INTO pvt VALUES (3,4,3,5,4,4); INSERT INTO pvt VALUES (4,4,2,5,5,4); INSERT INTO pvt VALUES (5,5,1,5,5,5); GO --Unpivot the table. SELECT VendorID, Employee, Orders FROM (SELECT VendorID, Emp1, Emp2, Emp3, Emp4, Emp5 FROM pvt) p UNPIVOT (Orders FOR Employee IN (Emp1, Emp2, Emp3, Emp4, Emp5) )AS unpvt; GO
相关文章推荐
- SQl2005行列转换 pivot/unpivot
- SQL 行列转换,sql2000和2005--多行转一行
- sql2005 行列转换的例子
- SQL 行列转换,sql2000和2005--多行转一行
- SQL2005 行列转换(巩固篇)
- sql2005 行列转换
- SQL 2005 行列转换 实例(函数PIVOT&UNPIVOT)
- SQL2005 行列转换(巩固篇)
- SQL2005 行列转换(巩固篇)
- SQL 行列转换简单示例
- 在SQL Server 2005中实现表的行列转换
- sql查询的行列转换
- 行列转换 经典SQL语句
- SQL行列转换,二次转换及添加‘小计‘、’总结’
- SQL普通行列转换
- sql行列转换
- 2005的行列转换
- SQL Server 2008 转换为 SQL 2005 数据库 脚本生成方式(解决主键、索引、标识等数据库约束丢失)
- 【SQL精彩语句】普通行列转换
- 瑞丽的SQL-SQL Server的表旋转(行列转换)