SQL Server中的数据透视示例 [英] Pivot Example in SQL Server

查看:108
本文介绍了SQL Server中的数据透视示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PLZ。给我一个多行的数据透视示例和关于数据透视的一些解释

&Syntax。

Plz. Give me a Pivot Example of Multiple Rows & some Explanation about Pivot
& Syntax.

推荐答案

我希望以下链接可以帮到你。



sql-server-pivot-and-unpivot-table-examples



pivot-tables-in-sql-server-a-simple-sample



getting-started-with-pivot-queries-in-sql-server-20052008
I hope the following links will help you.

sql-server-pivot-and-unpivot-table-examples

pivot-tables-in-sql-server-a-simple-sample

getting-started-with-pivot-queries-in-sql-server-20052008


hi,



pivot通过将表达式中一列中的唯一值转换为输出中的多列来旋转表值表达式,并执行任何需要它们的聚合在最终输出中需要的剩余列值。



示例





pivot rotates a table-valued expression by turning the unique values from one column in the expression into multiple columns in the output, and performs aggregations where they are required on any remaining column values that are wanted in the final output.

Example

select
   *
 from
 (
   select
     PS.Name, P.Color, PIn.Quantity
   from Production.Product P
   inner join Production.ProductSubcategory PS
     on PS.ProductSubcategoryID = P.ProductSubcategoryID
   left join Production.ProductInventory PIn
     on P.ProductID = PIn.ProductID
 ) DataTable
 PIVOT
 (
   SUM(Quantity)
   FOR Color
   IN (
     [Black],[Blue],[Grey],[Multi],[Red],
     [Silver],[Silver/Black],[White],[Yellow]
   )
 ) PivotTable


谷歌是你的朋友:好好经常拜访他。他可以比在这里发布问题更快地回答问题...



使用您的主题进行快速搜索,因为搜索字词超过400万次点击:数据透视表 [ ^ ]



将来,请尝试自己做至少基础研究,不要浪费你的时间或我们的时间。
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...

A very quick search using your subject as the search term gave over 4 million hits: Pivot Table[^]

In future, please try to do at least basic research yourself, and not waste your time or ours.

这篇关于SQL Server中的数据透视示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆