Core ideas for MDX select queries

Source: Internet
Author: User

MDX and TSQL are very different, the core idea of the MDX Select query statement is to slice the cube, and the aggregated value of the computed measure of the cube after the cut is the result of the query. Each slice cuts the cube to exclude members that do not meet the slicing criteria.

The schema of cube is very simple, with only two dimension and one measure Group.

1, an MDX statement that uses nested queries

SELECTNON EMPTY {[Measures].[Fact Product Inventory Count],[Measures].[Unit Cost]} onCOLUMNS from  (     SELECT( {[Dim Date].[Date Hierarchy].[Date Key].&[20050702]} ) onCOLUMNS from     (         SELECT( {[Dim Date].[Month number of year].&[7]} ) onCOLUMNS from         (             SELECT( {[Dim Product].[Product Hierarchy].[Product Category Key].&[1]} ) onCOLUMNS from [Adventure Works DW2012]        )    )) 

The role of a nested select is to slice the cube from the top to the outermost, in turn, by filtering out the members of product Category Key [1] in Cube, followed by [Dim Date]. [Month number of year]=[7], and then [Dim Date]. [Date Hierarchy]. [Date key]=[20050702], finally, the cube is filtered three times, and the remaining members are evaluated [Measures]. [Fact Product Inventory Count] and [Measures]. The aggregate value of [Unit cost] is the result of the query.

2, since MDX slices with a nested SELECT clause, you can convert to a WHERE clause and use the WHERE clause to slice the cube.

SELECTNON EMPTY {[Measures].[Fact Product Inventory Count],[Measures].[Unit Cost]} onCOLUMNS 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, slicing through rows

SELECTNON EMPTY {[Measures].[Fact Product Inventory Count],[Measures].[Unit Cost]} onCOLUMNS, {([Dim Product].[Product Hierarchy].[Product Category Key].&[1],         [Dim Date].[Month number of year].&[7],         [Dim Date].[Date Hierarchy].[Date Key].&[20050702])} onrows from [Adventure Works DW2012]

Core ideas for MDX select queries

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.