首页 > 解决方案 > MDX 查询中的 And-Or

问题描述

请考虑以下MDX查询:

SELECT {[Measures].[Internet Sales Amount]} ON COLUMNS,  
[Date].[Calendar Year].MEMBERS ON ROWS  
FROM [Adventure Works]  

如何WHERE使用以下三个条件将子句添加到上述查询:

1)在哪里[Customer].[Customer Geography].[Country].&[United States] AND [Product].[Category].&[Bike]

2)在哪里[Customer].[Customer Geography].[Country].&[United States] OR [Product].[Category].&[Bike]

3)在哪里([Customer].[Customer Geography].[Country].&[United States] OR [Product].[Category].&[Bike]) AND [Date].[Year].&[2008]

谢谢

标签: ssasmdxmdx-query

解决方案


1) [客户].[客户地理位置].[国家].&[美国] AND [产品].[类别].&[自行车]

为此,您的 where 子句将是

Where ([Customer].[Customer Geography].[Country].&[United States], [Product].[Category].&[Bike])

上面的代码定义了一个元组,它包含来自 United States Bikes Sales 的数据

2) [客户].[客户地理位置].[国家].&[美国] OR [产品].[类别].&[自行车]

为此,您的 Where 子句将是

Where 
{([Customer].[Customer Geography].[Country].&[United States], [Product].[Category].defaultmember),
([Customer].[Customer Geography].[Country].[Country], [Product].[Category].&[Bike])}

在这种情况下,您需要国家是美国或产品是自行车时的数据。所以我定义了两个元组,第一个表示国家是美国,产品类别可以是任何产品类别。在下一个元组中,我说国家可以是任何国家,但产品是自行车。在 MDX 中,集合中的每个 Tuple 在层次结构和层次结构的位置方面应该是相等的。在上述情况下,我无法做出一套说法

{
([Customer].[Customer Geography].[Country].&[United States]),
([Product].[Category].&[Bike])
}

这个集合在 MDX 中是不可能的,因此在第一个元组中我提到了“[Product].[Category].defaultmember”,这意味着没有定义特定的值,类似地在下一个元组中我使用了“[Customer].[Customer Geography] .[Country].[Country]" 因为这是用户层次结构,所以我不能使用默认成员,所以我使用了这个表达式。

3) Where ([Customer].[Customer Geography].[Country].&[United States] OR [Product].[Category].&[Bike]) AND [Date].[Year].&[2008]

为此,您需要修改 where 子句和 on 行。因此,对于这一部分,您的查询将是

SELECT {[Measures].[Internet Sales Amount]} ON COLUMNS,  
    [Date].[Calendar Year].&[2011] ON ROWS -- in my sample the strong name of 2011 is &[2011] yours may be diffrent 
    FROM [Adventure Works] 
    Where 
    {([Customer].[Customer Geography].[Country].&[United States], [Product].[Category].defaultmember),
    ([Customer].[Customer Geography].[Country].[Country], [Product].[Category].&[Bike])}

推荐阅读