在同一列-SSRS中显示两个不同的值

时间:2017-09-08 14:04:03

标签: sql sql-server reporting-services ssrs-2012

我需要创建一个报告(SSRS),但我无法弄清楚如何获得一个特定的值。 请考虑以下场景:我有一个层次结构国家/地区 - > City-> Person,&我需要为一个特定的人,一个特定的城市和一个列,在一列中获得财富的价值。一个特定的国家。 一个国家的财富不是生活在该国的人的财富的总和。 我的报告应该如下:

美国:20M $

   NY:                  3M$  
      Person1:        0,1M$ 
      Person2:        0,2M$

  Boston:             2M$

      Person 3:       0,5M$

................ 我的疑问是:

;WITH wealth_TEMP AS
(
    SELECT
        fo.wealthId,
        SUM(fo.wealth) AS wealth
        FROM
    (
        SELECT
            wealthId,
            CASE
                WHEN (Some Criteria)
                THEN 1
                ELSE 0
            END AS wealth
        FROM wealthTable f
    ) fo
    GROUP BY wealthId
),
Hierarchy AS
(
    SELECT 
        B.CityId AS CityId,
        B.CountryName AS CountryName
    FROM HierarchyTable AS B where
     b.CountryName IN (@Country)
),
Person_Table AS
(
    SELECT
        fsu.individualId,
        fsu.Cityid,
        fo.welth
    FROM Individual_Table FSU
    LEFT OUTER JOIN wealth_TEMP fo ON fo.wealthId = fsu.individualId
    WHERE bu.Cityname IN (@City)
)
Select ......................

1 个答案:

答案 0 :(得分:0)

考虑到您的数据集返回类似的内容:

Country CountryWealth State    StateWealth Person     PersonWealth  
USA     20M$          NY       3M$         Person 1    0,1M$
USA     20M$          NY       3M$         Person 2    0,2M$
USA     20M$          Boston   2M$         Person 3    0,5M$
  1. 创建一个包含5列的表并删除标题行
  2. 插入两个新的详细信息行
  3. 第一个行和第一个列中配置国家/地区并隐藏重复项为真
  4. 第一个行和第二个列中配置为CountryWealth并隐藏重复项为true
  5. 第二个行中,第二个列配置为State并隐藏重复项为true
  6. 第二个行中,第三个列配置为StateWealth并隐藏重复项为true
  7. 第三个行中,第三个到最后配置其他值
  8. 将表格分配给国家,州,人 可能,您需要添加更多列并合并以获得所需的lyout

相关问题