如何在sql中的数据透视表中创建多个聚合字段 [英] How to create multiple aggregate fields in pivot table in sql
本文介绍了如何在sql中的数据透视表中创建多个聚合字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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;
如何在此查询中添加多个聚合字段?
how to add mutiple aggregate field in this query?
推荐答案
您可以使用PIVOT,UNPIVOT
请使用以下链接
http://stackoverflow.com/questions/14694691/sql-server-pivot-table-with-multiple-column-aggregates [ ^ ]
http://beyondrelational.com/modules/2/blogs/88/Posts/14283/pivoting-on-multiple-columns-sql-server.aspx [ ^ ]
http:/ /connect.microsoft.com/SQLServer/feedback/details/236237/mutiple-aggregates-in-pivot [ ^ ]
You can use PIVOT, UNPIVOT
Please use following links
http://stackoverflow.com/questions/14694691/sql-server-pivot-table-with-multiple-column-aggregates[^]
http://beyondrelational.com/modules/2/blogs/88/Posts/14283/pivoting-on-multiple-columns-sql-server.aspx[^]
http://connect.microsoft.com/SQLServer/feedback/details/236237/mutiple-aggregates-in-pivot[^]
这篇关于如何在sql中的数据透视表中创建多个聚合字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文