0

Can anyone explain or show me example(s) what MDX can do and SQL can not do on same database? please...

1 Answer 1

0

It's not a matter of what one can do vs the other, as you can always, in theory, write SQL to replace your MDX. It's a matter of how hard it is.

Example:

If you want the sales per month of your top 5 clients from last year in EMEA, your MDX query is something like

SELECT TopCount( [Clients].Members, 5, ( [Measures].[Sales], [Time].[2018] ) ) on Rows, [Time].[2018].Children on Columns from [Sales] where [Geography].[EMEA] 

and your cube definition will take care of what columns to query from which tables, getting the Territory name from the dim_territory table, the customer name from the customer table, etc.

The equivalent in SQL would be something like

Select c.customer_name, t.month_name, sum(f.sales) from fact_sales f, dim_customer c, dim_time t, dim_geography g where f.time_id = t.time_id and f.customer_id = c.customer_id and f.geography_id = g.geography_id and g.territory = 'EMEA' and t.year= 2018 and c.customer_name in ( select c.customer_name, sum(f.sales) from fact_sales f, dim_customer c, dim_time t where f.customer_id = c.customer_id and f.time_id = t.time_id and t.year = 2018 group by t.year limit 5 ) group by t.year, t.month_name order by t.month_number 

Not only the SQL query is much more complex to write (I'm not even sure what I wrote is correct, tbh), but a lot of variations that in MDX just require a small rewrite, in SQL they will require several nested queries, and lots of filtering, grouping etc.

Plus, MDX allows you a cross-tab result, where you get one column for each month (or whatever dimension level you choose), whereas in SQL it will return a normalised dataset and you'll have to pivot it on the client side if you want it in tabular format.

3
  • Thanks a lot @nsousa , but I still need to know is there a query in MDX that no meeter how complicated is can not be done in SQL? It is part of my exam on PhD studies... Commented Apr 24, 2019 at 13:39
  • short answer: probably not. ROLAP is precisely that: translating MDX into SQL queries. Most likely many SQL queries, with results from previous ones being used in later ones. If memory and CPU power are infinite I don't see a reason why you wouldn't be able to translate any arbitrarily complex MDX query into an even more complex SQL one. The academic answer is probably no; the practical answer is "even if you can, you shouldn't" Commented Apr 25, 2019 at 10:56
  • OK. Thanks again. Commented Apr 25, 2019 at 13:44

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.