1

我使用 SQL Server 2008 R2,我使用 SSRS,我使用Adventure Work数据库。

我编写了这个 MDX 查询,以获取 2003 年和 2004 年都进入前十名的 10 个城市。

with 
set [Best Cities in CY 2003/2004] as
    intersect(
        order(
            topcount(
                [Customer].[Customer Geography].[City],
                10,
                (
                    [Measures].[Internet Sales Amount],
                    [Date].[Calendar].[Calendar Year].[CY 2003]
                )
            ),
            [Measures].[Internet Sales Amount],
            bdesc
        ),
        order(
            topcount(
                [Customer].[Customer Geography].[City],
                10,
                (
                    [Measures].[Internet Sales Amount],
                    [Date].[Calendar].[Calendar Year].[CY 2004]
                )
            ),
            [Measures].[Internet Sales Amount],
            bdesc
        )
    )
Select [Measures].[Internet Sales Amount] on columns,
       [Best Cities in CY 2003/2004] on rows
From [Adventure Works]
Where 
{
    [Date].[Calendar].[Calendar Year].[CY 2003],
    [Date].[Calendar].[Calendar Year].[CY 2004]
}

但我想获取互联网销售额与上一年相比下降 35% 的城市列表,以及同年排名前 10 的城市。

我怎样才能得到这个结果?

4

1 回答 1

3

您将Filter为此使用:

with 
set [Best Cities in CY 2003/2004] as
    filter(
        intersect(
            topcount(
                [Customer].[Customer Geography].[City],
                10,
                (
                    [Measures].[Internet Sales Amount],
                    [Date].[Calendar].[Calendar Year].[CY 2003]
                )
            ),
            topcount(
                [Customer].[Customer Geography].[City],
                10,
                (
                    [Measures].[Internet Sales Amount],
                    [Date].[Calendar].[Calendar Year].[CY 2004]
                )
            )
        ),
        ([Measures].[Internet Sales Amount], [Date].[Calendar].[Calendar Year].[CY 2004])
        /
        ([Measures].[Internet Sales Amount], [Date].[Calendar].[Calendar Year].[CY 2003])
        - 1.0
        < -0.35
    )
Select [Measures].[Internet Sales Amount] on columns,
       [Best Cities in CY 2003/2004] on rows
From [Adventure Works]
Where 
{
    [Date].[Calendar].[Calendar Year].[CY 2003],
    [Date].[Calendar].[Calendar Year].[CY 2004]
}
于 2013-08-29T08:12:10.103 回答