![]() | |
![]() |
| | Thread Tools | Display Modes |
#11
| |||
| |||
|
|
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 |
#12
| |||
| |||
|
|
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 |
#13
| |||
| |||
|
|
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 |
![]() |
| Thread Tools | |
| Display Modes | |
| |