Sql 将行值转换为列
我正在使用Reporting Services创建报告。我想显示存储在in列中的一些值。例如,假设我有一个表作为Sql 将行值转换为列,sql,sql-server,reporting-services,Sql,Sql Server,Reporting Services,我正在使用Reporting Services创建报告。我想显示存储在in列中的一些值。例如,假设我有一个表作为 Target | Type | Value - - - - - - - - - - - Store A |Type I | 4 Store A |Type II | 5 Store A |Type III | 16 Store B |Type I | 10 Store B |Type II | 25 我想把这些值列为: Target | Typ
Target | Type | Value
- - - - - - - - - - -
Store A |Type I | 4
Store A |Type II | 5
Store A |Type III | 16
Store B |Type I | 10
Store B |Type II | 25
我想把这些值列为:
Target | Type I | Type II | Type III
- - - - - - - - - - - - - - - - - - -
Store A |4|5|16
Store B |10|10|NULL(or 0)
下面是我现在如何处理这种情况的,我可以根据需要使用join,这样我就可以用column来显示这些值。然而,当数据太大时,它会像预期的那样导致太多问题。我想知道是否有更简单的方法来解决这个问题 您可以像这样在数据提取SQL查询中使用
select
[Target],[Type I],[Type II],[Type III]
from
(
select * from yourTbl
) src
PIVOT
(
Max([Value]) for [Type] in ([Type I],[Type II],[Type III])
)p
在tablix中对列进行分组,或者使用pivot在sql server中执行分组。如果列不是静态的,您可能需要动态透视。pivot解决了我的问题,但我也尝试了tablix,这也是一个很好的解决方案。非常感谢。