banjora {na+au+uk{auxilium}}

 

 

Our deepest apologies as this site is currently under construction... also,  this site is being developed with the new Opera 10 browser with speed dial... check it out!

 

 Opera, the fastest and most secure web rowser




dense_rank {aggregate, analytic function}

Posted: November 20, 2008 at 11:25 am by Liam A. Purefoy
No Comments
Filed Under: Development, Oracle RDBMS, plsql

first_value {analytical function}The Oracle SQL aggregate and analytic function DENSE_RANK computes the rank of a row in an ordered group of rows and returns the rank as a NUMBER. The ranks are consecutive integers beginning with 1.

The largest rank value is the number of unique values returned by the query. Rank values are not skipped in the event of ties. Rows with equal values for the ranking criteria receive the same rank. This function is useful for top-N and bottom-N reporting.

This function accepts as arguments any numeric datatype and returns NUMBER.

APPLIES TO: Oracle 9i, Oracle 10g, Oracle 11g

SYNTAX: DENSE_RANK() OVER (query_partition_clause order_by_clause)

 

AGGREGATE EXAMPLE: The following example computes the ranking of a hypothetical employee with the salary $15,500 and a commission of 5% in the sample table employees:

SELECT
 DENSE_RANK(15500, .05) WITHIN GROUP (ORDER BY emp.salary DESC,
emp.commission_pct) dense_rank
FROM
 employees emp;

dense_rank
3

 

ANALYTIC EXAMPLE: The following statement selects the department name, employee name, and salary of all employees who work in the human resources or purchasing department, and then computes a rank for each unique salary in each of the two departments. The salaries that are equal receive the same rank. Compare this example with the example for RANK.

SELECT
 dep.department_id,
 emp.last_name,
 emp.salary,
 DENSE_RANK() OVER (PARTITION BY emp.department_id ORDER BY emp.salary) as dense_rank
FROM
 employees emp,
 departments dep
WHERE
 emp.department_id = dep.department_id
 AND dep.department_id IN (‘60′, ‘90′);

department_id last_name salary dense_rank
60 Lorentz 4200 1
60 Pataballa 4800 2
60 Austin 4800 2
60 Ernst 6000 3
60 Hunold 9000 4
90 De Haan 17000 1
90 Kochhar 17000 1
90 King 24000 2

 

OVERVIEW: Aggregate functions return a single result row based on groups of rows, rather than on single rows. Aggregate functions can appear in select lists and in ORDER BY and HAVING clauses. They are commonly used with the GROUP BY clause in a SELECT statement, where Oracle Database divides the rows of a queried table or view into groups. In a query containing a GROUP BY clause, the elements of the select list can be aggregate functions, GROUP BY expressions, constants, or expressions involving one of these. Oracle applies the aggregate functions to each group of rows and returns a single result row for each group.

If you omit the GROUP BY clause, then Oracle applies aggregate functions in the select list to all the rows in the queried table or view. You use aggregate functions in the HAVING clause to eliminate groups from the output based on the results of the aggregate functions, rather than on the values of the individual rows of the queried table or view.

Analytic functions compute an aggregate value based on a group of rows. They differ from aggregate functions in that they return multiple rows for each group. The group of rows is called a ‘window’ and is defined by the analytic_clause. For each row, a sliding window of rows is defined. The window determines the range of rows used to perform the calculations for the current row. Window sizes can be based on either a physical number of rows or a logical interval such as time.

Analytic functions are the last set of operations performed in a query except for the final ORDER BY clause. All joins and all WHERE, GROUP BY, and HAVING clauses are completed before the analytic functions are processed. Therefore, analytic functions can appear only in the select list or ORDER BY clause.

  • Navigation
    • Home
    • About Us
    • Contact Us
    • Portfolio
    • Site Map
  • Categories
    • Development
    • Hardware
    • Informational
    • Linux
    • Oracle RDBMS
    • Oracle VM
    • plsql
    • Reviews
    • Software
    • VMware
    • Wordpress
    • Xen
  • Archives
    • August 2009
    • May 2009
    • February 2009
    • November 2008
    • February 2008
    • December 2007
    • November 2007
  • Recent Posts
    • Oracle VM 2.1.5 Server, Final Analysis
    • Installing Oracle VM 2.1.2 Server, Part I
    • The Differences Between Oracle 10g Releases
    • last & first {aggregate function}
    • cume_dist {aggregate, analytic function}
    • dense_rank {aggregate, analytic function}
    • first_value {analytical function}
    • Blocking Executables from an Oracle DB
    • Entrepreneurs benefit with Linkedin…
    • Treo 750 upgrade to Windows Mobile 6!

About Us

Welcome to Banjora [auxilium] entrepreneurs!

Promoting entrepreneurship by supplementing startup companies with viable technology solutions…

Please be patient… this website is currently being revised and energized….

isupport@banjora.com

Recent Postings

  • Oracle VM 2.1.5 Server, Final Analysis
  • Installing Oracle VM 2.1.2 Server, Part I
  • The Differences Between Oracle 10g Releases
  • last & first {aggregate function}
  • cume_dist {aggregate, analytic function}
  • dense_rank {aggregate, analytic function}
  • first_value {analytical function}
  • Blocking Executables from an Oracle DB
  • Entrepreneurs benefit with Linkedin…
  • Treo 750 upgrade to Windows Mobile 6!

Monthly Archives

  • August 2009
  • May 2009
  • February 2009
  • November 2008
  • February 2008
  • December 2007
  • November 2007

 

Category Cloud

    Development (8)
    Hardware (3)
    Informational (4)
    Linux (2)
    Oracle RDBMS (6)
    Oracle VM (2)
    plsql (6)
    Reviews (2)
    Software (4)
    VMware (2)
    Wordpress (1)
    Xen (2)

    WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.

Site Search

Site Navigation

  • Home
  • About Us
  • Contact Us
  • Portfolio
  • Site Map

banjora {na+au+uk{auxilium}} version 2.9.2 — 28 queries, 0.256 seconds

Entries RSS Comments RSS