MDX 查询中的 And-Or

And-Or in MDX queries

请考虑这个 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]

谢谢

1) Where [Customer].[Customer Geography].[Country].&[United States] AND [Product].[Category].&[Bike]

为此,您的 where 子句将是

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

以上代码定义了一个元组,其中包含来自美国自行车销售的数据

2) Where [Customer].[Customer Geography].[Country].&[United States] OR [Product].[Category].&[Bike]

为此,您的 Where 子句将是

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

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

{
([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])}