我需要创建一个报告(SSRS),但我无法弄清楚如何获得一个特定的值。 请考虑以下场景:我有一个层次结构国家/地区 - > City-> Person,&我需要为一个特定的人,一个特定的城市和一个列,在一列中获得财富的价值。一个特定的国家。 一个国家的财富不是生活在该国的人的财富的总和。 我的报告应该如下:
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 ......................
答案 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$
将表格分配给国家,州,人 可能,您需要添加更多列并合并以获得所需的lyout