我正在使用 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]