标签:
MDX和TSql有很大的不同,MDX select查询语句的核心思路是对cube进行切片,对切割后的cube计算Measure的聚合值就是查询的结果。每一次切片都将cube进行切割,剔除不满足切片条件的成员。
Cube的Schema非常简单,只有两个Dimension和一个Measure Group。
1,一个使用嵌套查询的MDX语句
SELECT NON EMPTY { [Measures].[Fact Product Inventory Count], [Measures].[Unit Cost] } ON COLUMNS FROM ( SELECT ( { [Dim Date].[Date Hierarchy].[Date Key].&[20050702] } ) ON COLUMNS FROM ( SELECT ( { [Dim Date].[Month Number Of Year].&[7] } ) ON COLUMNS FROM ( SELECT ( { [Dim Product].[Product Hierarchy].[Product Category Key].&[1] } ) ON COLUMNS FROM [Adventure Works DW2012] ) ) )
嵌套select的作用是从最内层到最外层,依次对cube进行切片,首先是将 cube中Product Category Key]为[1] 的成员筛选出来,其次将[Dim Date].[Month Number Of Year]=[7],然后[Dim Date].[Date Hierarchy].[Date Key]=[20050702],最后,cube经过三次筛选,余下的成员计算[Measures].[Fact Product Inventory Count]和 [Measures].[Unit Cost] 的聚合值,就是查询的结果。
2,既然MDX利用嵌套select子句进行切片,那么可以转换为where子句,使用where子句对cube进行切片。
SELECT NON EMPTY { [Measures].[Fact Product Inventory Count], [Measures].[Unit Cost] } ON COLUMNS FROM [Adventure Works DW2012] WHERE ( [Dim Product].[Product Hierarchy].[Product Category Key].&[1], [Dim Date].[Month Number Of Year].&[7], [Dim Date].[Date Hierarchy].[Date Key].&[20050702] )
3,通过Rows 进行切片
SELECT NON EMPTY { [Measures].[Fact Product Inventory Count], [Measures].[Unit Cost] } ON COLUMNS , {( [Dim Product].[Product Hierarchy].[Product Category Key].&[1], [Dim Date].[Month Number Of Year].&[7], [Dim Date].[Date Hierarchy].[Date Key].&[20050702] )} on rows from [Adventure Works DW2012]
标签:
原文地址:http://www.cnblogs.com/ljhdo/p/4611348.html