Thread: Applying LIMIT (dimen.) TO TOP (...) BASEDON (...) structure in OLAP_TABLE

This question is answered. Helpful answers available: 4. Correct answers available: 1.


Permlink Replies: 4 - Pages: 1 - Last Post: Nov 24, 2009 6:07 AM Last Post By: Piotr85 Threads: [ Previous | Next ]
Piotr85

Posts: 23
Registered: 10/16/09
Applying LIMIT (dimen.) TO TOP (...) BASEDON (...) structure in OLAP_TABLE
Posted: Nov 21, 2009 5:50 PM
 
Click to report abuse...   Click to reply to this thread Reply
Hi

I'd like to know how to apply structure

LIMIT dimension TO TOP (number of top member performers) BASEDON (measure)

in OLAP_TABLE.

For instance I have a cube SALES with 2 measures: SALES_VALUE and QUANTITY and a dimension PRODUCT with two levels: TOTAL and PRODUCT_NAME. Then I want to list 3 products with the highest SALES_VALUE and QUANTITY > 100.

I can create for example such query:

SELECT sales_val, quant, product_dsc
FROM TABLE(OLAP_TABLE(
'test_schema.test_aw DURATION SESSION',
null,
null,
'
MEASURE sales_val FROM sales_value
MEASURE quant FROM quantity

DIMENSION product WITH
HIERARCHY product_parentrel
INHIERARCHY product_inhier
ATTRIBUTE product_dsc FROM product_description

ROW2CELL r2c'))
WHERE
OLAP_CONDITION(R2C, 'LIMIT product TO product_levelrel eq ''PRODUCT_NAME''', 1)=1
AND OLAP_EXPRESSION_BOOL(R2C, ' quantity gt 100')=1
AND OLAP_CONDITION(R2C, 'LIMIT product TO TOP 3 BASEDON sales_value, 1)=1; ???????

Instruction above does not work completely well, because it will give 3 rows with top values of SALES_VALUE measure, but in this case OLAP_CONDITION(R2C, 'LIMIT product TO product_levelrel eq ''PRODUCT_NAME''', 1)=1 is not fulfilled (row with values of TOTAL_PRODUCT level appears).

One can create such query:

SELECT sales_val, quant, product_dsc
FROM TABLE(OLAP_TABLE(
'test_schema.test_aw DURATION SESSION',
null,
'LIMIT product TO TOP 3 BASEDON sales_value', ?????
'
MEASURE sales_val FROM sales_value
MEASURE quant FROM quantity

DIMENSION product WITH
HIERARCHY product_parentrel
INHIERARCHY product_inhier
ATTRIBUTE product_dsc FROM product_description

ROW2CELL r2c'))
where
OLAP_CONDITION(R2C, 'LIMIT product TO product_levelrel eq ''PRODUCT_NAME''', 1)=1
AND OLAP_EXPRESSION_BOOL(R2C, ' quantity gt 100')=1;

It leads to the same result as the first query.

What shuold I do to make OLAP_CONDITION(R2C, 'LIMIT product TO product_levelrel eq ''PRODUCT_NAME''', 1)
fulfill in query above?


I can add that query below works as it should (LIMIT TO TOP... omitted).

SELECT sales_val, quant, product_dsc
FROM TABLE(OLAP_TABLE(
'test_schema.test_aw DURATION SESSION',
null,
null,
'
MEASURE sales_val FROM sales_value
MEASURE quant FROM quantity

DIMENSION product WITH
HIERARCHY product_parentrel
INHIERARCHY product_inhier
ATTRIBUTE product_dsc FROM product_description

ROW2CELL r2c'))
WHERE
OLAP_CONDITION(R2C, 'LIMIT product TO product_levelrel eq ''PRODUCT_NAME''', 1)=1
AND OLAP_EXPRESSION_BOOL(R2C, ' quantity gt 100')=1;


Thank you in advance for any help

Peter

Shankar S.

Posts: 145
Registered: 03/23/06
Re: Applying LIMIT (dimen.) TO TOP (...) BASEDON (...) structure in OLAP_TABLE
Posted: Nov 22, 2009 7:48 AM   in response to: Piotr85 in response to: Piotr85
Helpful
Click to report abuse...   Click to reply to this thread Reply
Try using the limit as follows in olap_condition.

To get top 3 products sorted alphabetically according to dimension member id/value:
limit product to limit(limit(product to product_levelrel eq 'PRODUCT_NAME') keep top 3 basedon sales_value)

To get the top 3 products sorted based on sales_value:
limit product to limit(limit(limit(product to product_levelrel eq 'PRODUCT_NAME') keep top 3 basedon sales_value) sort top 3 basedon sales_value)

HTH
Shankar
Piotr85

Posts: 23
Registered: 10/16/09
Re: Applying LIMIT (dimen.) TO TOP (...) BASEDON (...) structure in OLAP_TABLE
Posted: Nov 22, 2009 4:09 PM   in response to: Piotr85 in response to: Piotr85
 
Click to report abuse...   Click to reply to this thread Reply
Hi

Thank you for your answer. It was really helpful. I had to modify it a bit to get it worked, because applying your way the condition about limiting to quantity qreater than 100 was omitted. I used:

OLAP_CONDITION(R2C, 'LIMIT product KEEP product_levelrel eq ''PRODUCT_NAME''', 1)=1
AND
OLAP_CONDITION(R2C, 'LIMIT product KEEP quantity gt 100',1)=1
AND
OLAP_CONDITION(R2C, 'LIMIT product KEEP TOP 3 BASEDON sales_value,1)=1
AND
OLAP_CONDITION(R2C, 'LIMIT product SORT TOP 3 BASEDON sales_value,1)=1

It does not omit condition about limiting to quantity qreater than 100 and returns 3 top performers, but still it is not sorted.

Regards

Peter

Shankar S.

Posts: 145
Registered: 03/23/06
Re: Applying LIMIT (dimen.) TO TOP (...) BASEDON (...) structure in OLAP_TABLE
Posted: Nov 22, 2009 10:56 PM   in response to: Piotr85 in response to: Piotr85
 
Click to report abuse...   Click to reply to this thread Reply
Peter, Yes, I hadn't considered the condition sales_value greater than 100 in my mail.

You can try either of the below limit cmds to include that condition too:
limit product to limit(limit(limit(product to (product_levelrel eq 'PRODUCT_NAME') AND (sales_value gt 100)) keep top 3 basedon sales_value) sort top 3 basedon sales_value)
-or-
limit product to limit(limit(limit(limit(product to product_levelrel eq 'PRODUCT_NAME') keep sales_value gt 100) keep top 3 basedon sales_value) sort top 3 basedon sales_value)

I dont think one can be sure that having separate olap_condition filters for each condition will work fine all the time. To simulate the cascading of AND operations of where clause (filters) in SQL, we can use the nested limit() function to act on progressively smaller/better qualified resultsets (cells). SQL query would apply the AND filters in any manner or order that the optimizer deems fit whereas using the limit function with keyword "keep" within it indicates an implicit order of filters. SQL query with multiple olap_conditions might rank and find top 3 -or- bottom 5 before it applies the filter "sales_value gt 100". In such a case, you may find that the query will return no rows or return only the top 1 or 2 out of top 3 which are gt 100 -or- in case of bottom, return no rows or return less than 5 members (only those above 100) -- not necessarily 3 "top 3" or 5 "bottom 5" members.

rgds
Shankar

Piotr85

Posts: 23
Registered: 10/16/09
Re: Applying LIMIT (dimen.) TO TOP (...) BASEDON (...) structure in OLAP_TABLE
Posted: Nov 24, 2009 6:07 AM   in response to: Piotr85 in response to: Piotr85
 
Click to report abuse...   Click to reply to this thread Reply
Hi

Thank you so much for your effort Shankar. Thanks to that I could really better understand how to use LIMIT command properly.

Regards

Peter
Legend
Guru Guru : 2500 - 1000000 pts
Expert Expert : 1000 - 2499 pts
Pro Pro : 500 - 999 pts
Journeyman Journeyman : 200 - 499 pts
Newbie Newbie : 0 - 199 pts
Oracle ACE Director
Oracle ACE Member
Oracle Employee ACE
Helpful Answer (5 pts)
Correct Answer (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums