dbTalk Databases Forums  

how to get specific values from multi-table function

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss how to get specific values from multi-table function in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Charles Hooper
 
Posts: n/a

Default Re: how to get specific values from multi-table function - 01-13-2008 , 11:24 AM






On Jan 13, 11:12*am, Maxim Demenko <mdeme... (AT) gmail (DOT) com> wrote:
Quote:
Since Oracle 9i, the need in the subquery is eliminated due to
FIRST/LAST functions ( which exists in both - analytical and aggregate -
form):

select inv_date,
max(prod_code) keep(dense_rank last order by total_sales),
max(total_sales)
from t1
group by inv_date

In case of ambiguos ordering criteria ( that is - if more than one
different products are topsellers, i.e. have exactly the same
total_sales) the result may be not as expected (it is valid for all
approaches - the traditional subquery, first/last or analytical approach
with numbering of rows by means of row_number(), rank() or dense_rank()
, in this case the query should be adjusted according to business
requirements - what should be returned as top seller, both products, any
one of them, none...)

Best regards

Maxim
max(prod_code) keep(dense_rank last order by total_sales)...

Thanks for posting the above explanation. I was not aware of the KEEP
syntax, and now I must again read the Oracle SQL Reference
documentation to see what else I missed.

Charles Hooper
IT Manager/Oracle DBA
K&M Machine-Fabricating, Inc.


Reply With Quote
  #12  
Old   
Charles Hooper
 
Posts: n/a

Default Re: how to get specific values from multi-table function - 01-13-2008 , 11:24 AM






On Jan 13, 11:12*am, Maxim Demenko <mdeme... (AT) gmail (DOT) com> wrote:
Quote:
Since Oracle 9i, the need in the subquery is eliminated due to
FIRST/LAST functions ( which exists in both - analytical and aggregate -
form):

select inv_date,
max(prod_code) keep(dense_rank last order by total_sales),
max(total_sales)
from t1
group by inv_date

In case of ambiguos ordering criteria ( that is - if more than one
different products are topsellers, i.e. have exactly the same
total_sales) the result may be not as expected (it is valid for all
approaches - the traditional subquery, first/last or analytical approach
with numbering of rows by means of row_number(), rank() or dense_rank()
, in this case the query should be adjusted according to business
requirements - what should be returned as top seller, both products, any
one of them, none...)

Best regards

Maxim
max(prod_code) keep(dense_rank last order by total_sales)...

Thanks for posting the above explanation. I was not aware of the KEEP
syntax, and now I must again read the Oracle SQL Reference
documentation to see what else I missed.

Charles Hooper
IT Manager/Oracle DBA
K&M Machine-Fabricating, Inc.


Reply With Quote
  #13  
Old   
Charles Hooper
 
Posts: n/a

Default Re: how to get specific values from multi-table function - 01-13-2008 , 11:24 AM



On Jan 13, 11:12*am, Maxim Demenko <mdeme... (AT) gmail (DOT) com> wrote:
Quote:
Since Oracle 9i, the need in the subquery is eliminated due to
FIRST/LAST functions ( which exists in both - analytical and aggregate -
form):

select inv_date,
max(prod_code) keep(dense_rank last order by total_sales),
max(total_sales)
from t1
group by inv_date

In case of ambiguos ordering criteria ( that is - if more than one
different products are topsellers, i.e. have exactly the same
total_sales) the result may be not as expected (it is valid for all
approaches - the traditional subquery, first/last or analytical approach
with numbering of rows by means of row_number(), rank() or dense_rank()
, in this case the query should be adjusted according to business
requirements - what should be returned as top seller, both products, any
one of them, none...)

Best regards

Maxim
max(prod_code) keep(dense_rank last order by total_sales)...

Thanks for posting the above explanation. I was not aware of the KEEP
syntax, and now I must again read the Oracle SQL Reference
documentation to see what else I missed.

Charles Hooper
IT Manager/Oracle DBA
K&M Machine-Fabricating, Inc.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.