您将如何订购MDX查询

时间:2015-07-10 18:41:52

标签: mdx

我无法弄清楚如何做一个简单的“order by”子句。

以下是我的查询 - 如何按Service Name然后按Adjusted Incidents订购?

SELECT 
  {[Measures].[Adjusted Incidents]} ON COLUMNS
 ,NON EMPTY 
    {
        [Completed Inspections].[Service Name].[Service Name].ALLMEMBERS
      * 
        [Inspected Items].[Item Name].[Item Name].ALLMEMBERS
    }
  DIMENSION PROPERTIES MEMBER_CAPTION  ON ROWS
FROM 
(
  SELECT 
    {
      [Completed Inspections].[Customer Id].&[DRHOD]
     ,[Completed Inspections].[Customer Id].&[EMHST]
     ,[Completed Inspections].[Customer Id].&[EXHOU]
     ,[Completed Inspections].[Customer Id].&[ETRAD]
    } ON COLUMNS
  FROM [Inspections]
)
WHERE 
  (
    [Calendar].[Month].&[2015-05-01T00:00:00]
   ,[Completed Inspections].[Is Reinspection].&[False]
  )
CELL PROPERTIES VALUE;

1 个答案:

答案 0 :(得分:1)

mdx中没有与sql类似的订单条款。

您需要将函数ORDER应用于您要订购的任何集合。以下是msdn定义:
https://msdn.microsoft.com/en-us/library/ms145587.aspx

mdx中嵌套订单并不是那么简单 - 订单的内部应用程序是您要应用的订单,第二个外部嵌套是您首先要应用的订单:

SELECT 
  {[Measures].[Adjusted Incidents]} ON COLUMNS
 ,NON EMPTY 
    Order
    (
      Order
      (
        {
            [Completed Inspections].[Service Name].[Service Name].ALLMEMBERS
          * 
            [Inspected Items].[Item Name].[Item Name].ALLMEMBERS
        }
       ,[Measures].[Adjusted Incidents]
       ,BDESC  //<<you have 4 choices here BDESC, BASC, DESC, or ASC
      )
     ,[Completed Inspections].[Service Name].CurrentMember.Member_Caption
     ,BDESC    //<<you have 4 choices here BDESC, BASC, DESC, or ASC
    )
  DIMENSION PROPERTIES MEMBER_CAPTION  ON ROWS
FROM 
(
  SELECT 
    {
      [Completed Inspections].[Customer Id].&[DRHOD]
     ,[Completed Inspections].[Customer Id].&[EMHST]
     ,[Completed Inspections].[Customer Id].&[EXHOU]
     ,[Completed Inspections].[Customer Id].&[ETRAD]
    } ON COLUMNS
  FROM [Inspections]
)
WHERE 
  (
    [Calendar].[Month].&[2015-05-01T00:00:00]
   ,[Completed Inspections].[Is Reinspection].&[False]
  )
CELL PROPERTIES VALUE;