0

我正在使用 MDX 和 Microsoft SQL Server 2008 Analysis Services。我有一个具有以下尺寸的 Shipments 多维数据集:

* Measures: Quantity
* Time: Year/Month/Day
* Ship Date: Year/Month/Day
* Receipt Date: Year/Month/Day

我想知道每个月最后一天在途的数量。我怎样才能做到这一点?在 SQL 中,它会是这样的:

SELECT
  A.[Month], SUM(B.[Quantity]) AS [In Transit]
FROM
  ( SELECT [Month], MAX([Day]) AS [End of Month] FROM [Time] GROUP BY [Month] ) A
  CROSS JOIN
  ( SELECT [Quantity], [Ship Date], [Receipt Date] FROM [Shipments] ) B
WHERE
  B.[Ship Date] <= A.[End of Month]
  AND B.[Receipt Date] > A.[End of Month]
GROUP BY
  A.[Month]
4

1 回答 1

1

以下查询在 AdventureWorks 中运行,即语法正确。AdventureWorks 的结构与您的立方体非常相似。您的多维数据集的主要更改将是度量、层次结构和多维数据集名称的适应;由于您没有详细说明这些,我留下了查询,以便它在 AdventureWorks 中运行:

with member [Measures].[In Transit] as
     Sum((null : LinkMember([Date].[Calendar].CurrentMember, [Ship Date].[Calendar]))
          *
         (LinkMember([Date].[Calendar].CurrentMember.NextMember, [Delivery Date].[Calendar]) : null),
         [Measures].[Internet Sales Amount]
        )
select { [Measures].[In Transit] }
       on columns,
       [Date].[Calendar].[Month].Members
       on rows
from [Adventure Works]

LinkMember从具有相同结构的层次结构中获取对应的成员,通常是基于相同维度表的角色扮演维度。和结构分别返回所有成员的集合null : <some member>,或从同一级别的末尾开始的所有成员。<some member> : null<some member><some member>

于 2013-10-08T18:12:58.970 回答