SQL to MDX Where IN子句

时间:2014-11-17 11:39:56

标签: ssas mdx

我遇到需要制定MDX查询的情况。相应的SQL查询类似于:

SELECT no_of_downloads 
FROM   table_1
WHERE  project_code IN ('abc', 'def', 'ghi' , .....)

我制定了以下MDX查询,但我一次只能将它用于一个项目代码。

SELECT 
  [Measures].[#Activity] ON COLUMNS
 ,Filter
  (
    [Organisation Dimension].[Txt Project Code].MEMBERS
   ,
    [Organisation Dimension].[Txt Project Code].CurrentMember.Name = 'KM_BNG'
  ) ON ROWS
FROM [Activity Cube]
WHERE 
  (
    [Activity Dimension].[Txt Activity Name].&[Download]
   ,[System Dimension].[Txt System Name].&[KShop] //ENTER CODE HERE//
   ,[Time Dimension].[Fiscal Hierarchy].[Fiscal Half Year Name].&[2014-04-01T00:00:00]
  );

如何在列表中添加更多项目代码?

2 个答案:

答案 0 :(得分:2)

或者如果您真的热衷于使用WHERE子句,那么只需将FrankPI创建的SET移动到WHERE子句中。

WHERE子句在概念上是一个轴,作为MDX的规则,相同的层次结构不能放在多个轴上,您需要将它从ROWS移动到这样:

SELECT 
  [Measures].[#Activity] ON 0
FROM [Activity Cube]
WHERE 
  (
    [Activity Dimension].[Txt Activity Name].&[Download]
   ,[System Dimension].[Txt System Name].&[KShop]
   ,{
       [Organisation Dimension].[Txt Project Code].[KM_BNG],
       [Organisation Dimension].[Txt Project Code].[other name],
       [Organisation Dimension].[Txt Project Code].[third name]
    }
   ,[Time Dimension].[Fiscal Hierarchy].[Fiscal Half Year Name].&[2014-04-01T00:00:00]
  );

在您希望包含层次结构[Organisation Dimension].[Txt Project Code]的50个成员的极端情况下,可以在多维数据集脚本中更好地管理它。您可以创建一个集[myTxtProjectCodes],然后MDX会更简单:

SELECT 
  [Measures].[#Activity] ON 0
FROM [Activity Cube]
WHERE 
  (
    [Activity Dimension].[Txt Activity Name].&[Download]
   ,[System Dimension].[Txt System Name].&[KShop]
   ,{
       [myTxtProjectCodes]
    }
   ,[Time Dimension].[Fiscal Hierarchy].[Fiscal Half Year Name].&[2014-04-01T00:00:00]
  );

答案 1 :(得分:1)

您不需要过滤器,您只需枚举花括号中ON ROWS子句中的成员:

SELECT [Measures].[#Activity]
       ON COLUMNS ,
       {
       [Organisation Dimension].[Txt Project Code].[KM_BNG],
       [Organisation Dimension].[Txt Project Code].[other name],
       [Organisation Dimension].[Txt Project Code].[third name]
       }
       ON ROWS
...