SSRS行值到列

时间:2017-05-10 11:24:02

标签: sql sql-server reporting-services

我正在使用Reporting Services创建报告。我想显示存储在列中的一些值。例如,假设我有一个表格作为;

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,因此我可以在colums中显示这些值。但是,当数据太大时,会导致太多问题。我想知道是否有更简单的方法来解决这个问题?

2 个答案:

答案 0 :(得分:1)

您可以在数据提取SQL查询中使用PIVOT,如此

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

答案 1 :(得分:1)

tablix https://www.youtube.com/watch?v=zM5DRsnH3E0中的组列或使用pivot在sql server中执行分组。 https://docs.microsoft.com/en-us/sql/t-sql/queries/from-using-pivot-and-unpivot如果列不是静态的,则可能需要动态数据透视。

相关问题