以编程方式生成MDX rowcount查询的最简单方法?

时间:2015-02-02 16:21:39

标签: sql mdx olap

现在我正在处理一个可以生成并返回SQL或MDX查询的程序(取决于查询的源数据库)。我正在努力添加一项功能,该功能可以计算给定查询返回的所有行。

现在,我有一些SQL的小背景,所以我能够解析表名并生成一个rowcount。但是,MDX对我来说是一个全新的野兽。

在SQL中,我正在创建:

SELECT 
   COUNT(SUM)
AS ROWS
FROM
(
  COUNT(*) AS COUNT FROM TABLE1
  UNION ALL
  COUNT(*) AS COUNT FROM TABLE2
  UNION ALL
  COUNT(*) AS COUNT FROM TABLE3
  ETC...
)

现在,我想知道的是,我将如何与MDX做类似的事情?我已经对MDX做了一些阅读,从我收集到的基本符号是

[Dimension].[Hierarchy].[Level]

现在使用SQL,我从更大的生成查询中解析表名,并将它们简单地插入到以编程方式生成的新查询中。我需要从更大的MDX查询中获取什么来生成我自己的行计数查询并将其发送出去?我正在处理的MDX的一个更简单的例子是:

 WITH
     MEMBER [BUSINESS1].[XQE_RS_CM1] AS '([BUSINESS1].[COMPANY_H].[all])', SOLVE_ORDER = 8
     MEMBER [BUSINESS2].[XQE_RS_CM0] AS '([BUSINESS2].[all])', SOLVE_ORDER = 4
SELECT 
     NON EMPTY {[BUSINESS2].[ALL_TIME_H].[CALENDAR_YEAR_L].MEMBERS AS [XQE_SA1] , HEAD({[BUSINESS2].[XQE_RS_CM0]}, COUNT(HEAD([XQE_SA1]), INCLUDEEMPTY))} DIMENSION PROPERTIES PARENT_LEVEL,  PARENT_UNIQUE_NAME ON AXIS(0), 
     NON EMPTY {[BUSINESS1].[COMPANY_H].[COMPANY_CD__L].MEMBERS AS [XQE_SA0] , HEAD({[BUSINESS1].[XQE_RS_CM1]}, COUNT(HEAD([XQE_SA0]), INCLUDEEMPTY))} DIMENSION PROPERTIES PARENT_LEVEL,  PARENT_UNIQUE_NAME ON AXIS(1), 
     NON EMPTY {[Measures].[Measures].[BUSINESS3]} DIMENSION PROPERTIES PARENT_LEVEL,  PARENT_UNIQUE_NAME ON AXIS(2)
FROM 
    [SOURCE]  CELL PROPERTIES CELL_ORDINAL,  FORMAT_STRING,  VALUE

任何见解都会很棒,谢谢。

1 个答案:

答案 0 :(得分:1)

乍一看,你的脚本看起来很合理,然后解开它后会变得有点(!)更复杂。

这个和其他脚本的主要区别在于它使用了轴(2)。在子选择中经常使用额外的维度,但这有点奇怪,因为大多数客户端无法处理3维单元集 - 所以我对消费这些信息的东西很感兴趣?

成员[BUSINESS1].[XQE_RS_CM1]也是[BUSINESS2].[XQE_RS_CM0]的单个成员,那么HEAD...部分的重点是什么?

WITH
     MEMBER [BUSINESS1].[XQE_RS_CM1] AS 
         ([BUSINESS1].[COMPANY_H].[all]), SOLVE_ORDER = 8
     MEMBER [BUSINESS2].[XQE_RS_CM0] AS 
         ([BUSINESS2].[all]), SOLVE_ORDER = 4
SELECT 
     NON EMPTY 
         {[BUSINESS2].[ALL_TIME_H].[CALENDAR_YEAR_L].MEMBERS AS [XQE_SA1] 
         ,HEAD(
            {[BUSINESS2].[XQE_RS_CM0]}, 
            COUNT(
              HEAD([XQE_SA1])
             ,INCLUDEEMPTY
            )
          )}
     ON AXIS(0), 
     NON EMPTY 
         {[BUSINESS1].[COMPANY_H].[COMPANY_CD__L].MEMBERS AS [XQE_SA0] 
         ,HEAD(
            {[BUSINESS1].[XQE_RS_CM1]}, 
            COUNT(
              HEAD([XQE_SA0])
             ,INCLUDEEMPTY
            )
          )}
     ON AXIS(1), 
     NON EMPTY 
        {
          [Measures].[Measures].[BUSINESS3]
        } 
     ON AXIS(2)
FROM 
    [SOURCE]

以下内容是否返回与原始脚本相同的数据?

SELECT 
     NON EMPTY 
         {
          [BUSINESS2].[ALL_TIME_H].[CALENDAR_YEAR_L].MEMBERS 
         ,[BUSINESS2].[all]
         }
     ON 0, 
     NON EMPTY 
         {
          [BUSINESS1].[COMPANY_H].[COMPANY_CD__L].MEMBERS
         ,[BUSINESS1].[COMPANY_H].[all]
         }
     ON 1
FROM  [SOURCE]
WHERE [Measures].[Measures].[BUSINESS3];

然后您需要计算的是在行中的以下集合中返回的成员数:

{
  [BUSINESS1].[COMPANY_H].[COMPANY_CD__L].MEMBERS
 ,[BUSINESS1].[COMPANY_H].[all]
}