0

Good Afternoon,

I am new to OLAP (and dabatases in general). I need to write a query to retrieve the TOP 10 sales for a year by product.

To do so I would have to work with three tables (simplified just to show the main structure):

LOCATION(location_id,country,....,city,....,district_id),
SALES_A(shop_id, product_id,....., unit_sales,....., unit_price),
SALES_B(shop_id, product_id,...., unit_sales, unit_price),
SHOP(shop_id,....,location_id,.....)

The structure of the query I need to write using RANK() should be clear from the examples I have seen but my main doubt comes from a comment made in this video https://www.youtube.com/watch?v=pmpzsws4xwA&t=12s about the point of using Analytical Functions to avoid using self joins.

Since all the examples I have seen so far use only a single table, and because of the comment made on the linked video, my question is...within the context of a Data Warehouse, is it OK to do joins between the different tables needed, and then apply analytical functions to the resulting table?.

Does this incurr in a performance penalty and should be done in a different way?

Many thanks in advance

Sergi
  • 471
  • 3
  • 13
  • Make it easy to assist you: [mcve] – jarlh Mar 16 '20 at 14:57
  • Hi Jarlh, thanks for your reply. I didn't provided any code, since my main issue is conceptual, I have seen how analytical functions are applied on a table, but I haven't seen an example where several tables have to be joined beforehand. I can write the code for the joins I would do etc, but my main question remains as to whether using Joins is acceptable withing the Data Warehouse context, or whether there is a different/better way of doing it. – Sergi Mar 16 '20 at 15:03
  • [Why should I tag my DBMS](https://meta.stackoverflow.com/questions/388759/) –  Mar 16 '20 at 15:28
  • 1
    "*is it OK to do joins between the different tables needed, and then apply analytical functions to the resulting table?*" - yes, of course. Why shouldn't it be OK if it solves your problem and runs in acceptable time? –  Mar 16 '20 at 15:29
  • Many thanks!!!, I wasn't sure whether I missed on a fancier way of joining data in a D.W. – Sergi Mar 16 '20 at 15:42

0 Answers0