

Window sizes can be based on either a physical number of rows or a logical interval such as time.Īnalytic functions are the last set of operations performed in a query except for the final ORDER BY clause. The window determines the range of rows used to perform the calculations for the current row. For each row, a sliding window of rows is defined. The group of rows is called a window and is defined by the analytic_clause.

They differ from aggregate functions in that they return multiple rows for each group. This calculation evaluates the inner aggregate ( MAX( salary)) for each group defined by the GROUP BY clause ( department_id), and aggregates the results again.Īnalytic functions compute an aggregate value based on a group of rows. SELECT AVG(MAX(salary)) FROM employees GROUP BY department_id For example, the following example calculates the average of the maximum salaries of all the departments in the sample schema hr: Please refer to FIRST for more information. The aggregate functions MIN, MAX, SUM, AVG, COUNT, VARIANCE, and STDDEV, when followed by the KEEP keyword, can be used in conjunction with the FIRST or LAST function to 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. For all the remaining aggregate functions, if the data set contains no rows, or contains only rows with nulls as arguments to the aggregate function, then the function returns null. COUNT never returns null, but returns either a number or zero. You can use the NVL function in the argument to an aggregate function to substitute a value for a null. If you specify neither, then the default is ALL.Īll aggregate functions except COUNT(*) and GROUPING ignore nulls. Many (but not all) aggregate functions that take a single argument accept these clauses:ĭISTINCT causes an aggregate function to consider only distinct values of the argument expression.ĪLL causes an aggregate function to consider all values, including all duplicates.įor example, the DISTINCT average of 1, 1, 1, and 3 is 2. See Also: "Using the GROUP BY Clause: Examples" and the "HAVING Clause" for more information on the GROUP BY clause and HAVING clauses in queries and subqueries The remaining datetime functions were designed to accept any of the three types of data (date, timestamp, and interval) and to return a value of one of these types. The exceptions are the MONTHS_BETWEEN function, which returns a number, and the ROUND and TRUNC functions, which do not accept timestamp or interval values at all. If you provide a timestamp value as their argument, Oracle Database internally converts the input type to a DATE value and returns a DATE value. Some of the datetime functions were designed for the Oracle DATE datatype ( ADD_MONTHS, CURRENT_DATE, LAST_DAY, NEW_TIME, and NEXT_DAY).

Datetime functions operate on date ( DATE), timestamp ( TIMESTAMP, TIMESTAMP WITH TIME ZONE, and TIMESTAMP WITH LOCAL TIME ZONE), and interval ( INTERVAL DAY TO SECOND, INTERVAL YEAR TO MONTH) values.
