Questions tagged [analytic-functions]

Aggregation functions that can peek at rows returned from the same query. The SQL standard defines them as window functions and the tag `window-functions` should be preferred over `analytical-functions` unless it is something completely Oracle specific

From Oracle documentation page: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions004.htm#SQLRF06174

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.

Analytic functions are commonly used to compute cumulative, moving, centered, and reporting aggregates.

244 questions
6
votes
2 answers

Interesting Oracle analytic query challenge

I'm fairly experienced with Oracle analytic functions but this one has stumped me. I'll kick myself if there's an obvious solution :) I have a table, JOURNAL, which records Inserts, Updates and Deletes on another table. The table that it's a journal…
Jeffrey Kemp
  • 59,135
  • 14
  • 106
  • 158
6
votes
3 answers

Remove ORDER BY clause from PARTITION BY clause?

Is there a way I can reduce the impact of the 'ORDER BY lro_pid' clause in the OVER portion of the inner query below? SELECT * FROM (SELECT a.*, Row_Number() over (PARTITION BY search_point_type …
drapkin11
  • 1,205
  • 2
  • 12
  • 24
6
votes
4 answers

Creating a custom, multi-argument Oracle analytic function

Background I know that in Oracle it's possible to create custom aggregate functions that process a collection of values and return a single result. Edit: I've even read the friendly manual at…
Bryant
  • 622
  • 4
  • 18
6
votes
1 answer

Oracle Analytic Rolling Percentile

Is it possible to use windowing with any of the percentile functions? Or do you know a work around to get a rolling percentile value? It is easy with a moving average: select avg(foo) over (order by foo_date rows between 20…
anti_ml
  • 481
  • 4
  • 15
5
votes
1 answer

In which scenarios does SQL Server ROW_NUMBER() not start from 1?

We are using ROW_NUMBER() in our query. It is returning correct results in almost all scenarios. But for 1 user, it is behaving very differently. With #TEST as ( select top 50 ROW_NUMBER() over (order by a.ID) as RN, a.ID ID,…
user1049008
  • 61
  • 2
  • 4
5
votes
2 answers

Getting values relating to the max and min rows in Oracle

In Oracle 11g we need to be able to query a table to pull out information from rows with the highest and lowest values in a certain group. For example using the EMP table we'd like to find the name of person with the highest salary and the name of…
Richard Craggs
  • 155
  • 1
  • 2
  • 7
5
votes
2 answers

Displaying a single rank in MySQL table

I have a table called 'highscores' that looks like this. id udid name score 1 1111 Mike 200 2 3333 Joe 300 3 4444 Billy 50 4 0000 Loser 10 5 DDDD …
user261362
5
votes
1 answer

Hibernate Criteria with Oracle analytic windowing function

Trying to override Oracle10gDialect and adding in over and partition functions. I read on hibernate.org about how to override the dialect. I am using Hibernate 4.1.7.Final and cannot upgrade. I implemented it as specified, however i am getting this…
5
votes
3 answers

Oracle Analytic functions - resetting a windowing clause

I have the following data set. create table t1 ( dept number, date1 date ); Table created. insert into t1 values (100, '01-jan-2013'); insert into t1 values (100, '02-jan-2013'); insert into t1 values (200, '03-jan-2013'); insert into t1…
Rajesh Chamarthi
  • 18,568
  • 4
  • 40
  • 67
4
votes
1 answer

SQL - ROW_NUMBER () OVER (ORDER BY) not working

It doesn't matter what I put in the ORDER BY clause, the order of the result set doesn't change. WITH Results AS ( SELECT DISTINCT MessageThreadUsers.threadFK, MessageThreads.threadDate, Messages.MessageBody, …
Redtopia
  • 4,947
  • 7
  • 45
  • 68
4
votes
3 answers

How can I perform linear interpolation using oracle SQL?

I am trying to use Oracle 11g (11.1 in dev, 11.2 in production) for numeric analysis, specifically linear interpolation on a table which has three columns of interest: a timestamp, a deviceid, and value. The value columns holds data from the device…
GLaDOS
  • 683
  • 1
  • 14
  • 29
4
votes
2 answers

rank a column with out ordering in oracle

I have the data as below, When I apply dense_rank by ordering id column, I am getting rank according to the order of integers but I need to rank as the records are displayed when run a query: Data from query: Rid id 8100 161 8101 2 8102 …
Siva
  • 9,043
  • 12
  • 40
  • 63
4
votes
1 answer

Oracle Version 10 - Do we need anything 'special' to run analytic functions

We're going to be deploying some code to a client who is using Oracle version 10. Some of our code uses Oracle analytic functions (LAG in particular). Is there anything special that needs to be installed/allowed permissiosn/etc. for the code using…
contactmatt
  • 18,116
  • 40
  • 128
  • 186
4
votes
3 answers

How to get running total from consecutive columns in Oracle SQL

I have troubles to display consecutive holidays from an existing date dataset in Oracle SQL. For example, in December 2017 between 20th and 30th, there are the following days off (because Christmas and weekend days): 23.12.2017 Saturday 24.12.2017…
Ivo
  • 303
  • 2
  • 15
4
votes
4 answers

Evaluate WHERE predicates on analytic functions before other predicates (Oracle analytic functions)

Background Sample data set #Employee Id | Period | Status --------------------- 1 | 1 | L 1 | 2 | G 2 | 3 | L I want a simple select query to yield employees' latest record (by period) only if the status='L'. The results…
1
2
3
16 17