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




last & first {aggregate function}

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

first_value {analytical function}The Oracle SQL aggregate FIRST and LAST are very similar functions. Both are aggregate and analytic functions that operate on a set of values from a set of rows that rank as the FIRST or LAST with respect to a given sorting specification. If only one row ranks as FIRST or LAST, the aggregate operates on the set with only one element.

This function takes as an argument any numeric datatype or any nonnumeric datatype that can be implicitly converted to a numeric datatype. The function returns the same datatype as the numeric datatype of the argument.

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

SYNTAX: aggregate_function(column_name) KEEP (DENSE_RANK FIRST ORDER BY column_name [ASC|DESC NULLS FIRST|LAST) OVER (PARTITION BY column_name)

AGGREGATE EXAMPLE: The following example returns, within each department of the sample table employees, the minimum salary among the employees who make the lowest commission and the maximum salary among the employees who make the highest commission:

SELECT
 emp.last_name,
 emp.department_id,
 emp.salary,
 MIN(emp.salary) KEEP (DENSE_RANK FIRST ORDER BY emp.commission_pct) OVER
(PARTITION BY emp.department_id) min_salary,
 MAX(emp.salary) KEEP (DENSE_RANK LAST ORDER BY emp.commission_pct) OVER
(PARTITION BY emp.department_id) max_salary
FROM
 employees emp
WHERE
 emp.department_id in (20, 30)
ORDER BY emp.department_id, emp.salary;

last_name department_id salary min_salary max_salary
Fay 20 6000 6000 13000
Hartstein 20 13000 6000 13000
Colmenares 30 2500 2500 11000
Himuro 30 2600 2500 11000
Tobias 30 2800 2500 11000
Baida 30 2900 2500 11000
Khoo 30 3100 2500 11000
Raphaely 30 11000 2500 11000

 

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.267 seconds

Entries RSS Comments RSS