【问题标题】:intersect and topcount and order function in MDX queryMDX 查询中的 intersect 和 topcount 和 order 函数
【发布时间】:2013-08-28 09:46:47
【问题描述】:

我使用 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 的城市。

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

【问题讨论】:

  • 您的意思是:在 2004 年排名前 10 的城市中,您希望拥有那些销售额下降 35% 或更多的城市?或者您是否希望看到 2004 年销售额下降 35% 或更多的城市或位于前 10 名销售额之内的城市?
  • 我想得到 2004 年和 2003 年销售额最好的 10 个城市,而这个城市在 2003 年和 2002 年的销售额下降了 35% 或更多?

标签: sql sql-server-2008-r2 ssas mdx olap


【解决方案1】:

您可以为此使用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]
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-21
    • 1970-01-01
    • 1970-01-01
    • 2012-12-28
    相关资源
    最近更新 更多