在 T-SQL 中,我只需在 select 语句中使用 group by 子句和 count(*) 来给我需要的值。但是对于多维数据集,情况就不同了,因为计数不仅仅是行数,而是维度组合。所以我用谷歌搜索了一个无济于事的答案。这是我的问题的详细解释:
我原来的MDX是:
SELECT
NON EMPTY
{
[Measures].[Budget]
} ON COLUMNS
,NON EMPTY
{
[Location].[Category - Entity - Facility].[Facility].ALLMEMBERS*
[Location].[Category - Facility - Unit].[Location].ALLMEMBERS*
[Calendar].[Day].[Day].ALLMEMBERS
} ON ROWS
FROM
(
SELECT
{[Location].[Category - Entity - Facility].[Category].&[3]} ON COLUMNS
FROM
(
SELECT
[Calendar].[Year - Quarter - Month - Day].[Day].&[2012-01-01T00:00:00]
: [Calendar].[Year - Quarter - Month - Day].[Day].&[2012-05-31T00:00:00]
ON COLUMNS
FROM [PHI Census]
)
)
Results look like this:
Facility 1 Location 1 Day 1 100
Facility 1 Location 1 Day 2 100
Facility 1 Location 1 Day 3 100
Facility 1 Location 1 Day 4 100
Facility 1 Location 2 Day 1 80
Facility 1 Location 2 Day 2 80
Facility 1 Location 2 Day 3 80
Facility 2 Location 1 Day 1 65
Facility 2 Location 1 Day 2 65
Facility 2 Location 1 Day 3 65
Facility 2 Location 1 Day 4 65
Facility 2 Location 2 Day 1 73
Facility 2 Location 2 Day 2 73
Facility 2 Location 2 Day 3 73
这给了我为每个设施-位置-日组合列出一次的 [预算]。我想从 ON ROWS 子句中删除 [Calendar].[Day].[Day].ALLMEMBERS 并简单地使用一个计算成员,该成员将返回每个 Facility-Location 组合以及每一行的天数。所以基本上,
The results would look like this:
Facility Location Budget DayCount
Facility 1 Location 1 100 4
Facility 1 Location 2 80 3
Facility 2 Location 1 65 4
Facility 2 Location 2 73 3