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
1
vote
1 answer

Oracle Collect Over Analytical Function

Is it possible to use the 10g collect command as an analytical function by using OVER PARTITION or some other way? e.g. SELECT COLLECT(x) OVER (PARTITION BY y) FROM table Every time I try this there is a ora 3113 exception saying 'end-of-file on…
Chris
  • 2,447
  • 1
  • 21
  • 27
1
vote
1 answer

Rolling averages in SQL Server 2012 using range

I’m trying to calculate a 3 month rolling average grouped by region and month, as in Region Month Avg(var_a) Avg(var_b) Northland Dec-Jan-Feb 7.1 5.9 Southland Dec-Jan-Feb 7.2 6.1 Northland…
corrin
  • 63
  • 1
  • 6
1
vote
1 answer

Nested analytic functions in Oracle

Can we use nested analytic function within analytic function? We can use another analytic function within expression or not? Please provide me one example.
MrYo
  • 1,797
  • 3
  • 19
  • 33
1
vote
1 answer

Eliminating similar row but with specific values

I have user table and user_group table. A single user can be in multiple group. I have two groups admin and user. Admin group has group id 1 and user group has group id 2. As I select from joining these two table. I would like to select it using…
kinkajou
  • 3,664
  • 25
  • 75
  • 128
1
vote
1 answer

Oracle get first preceding and following rows ordered by time in another table

I have 2 tables each of which have a timestamp column. How do I query for each row in A, the first preceding and following timestamps in B ? I want: A.id A.timestamp first_preceding(B.timestamp) first_following(B.timestamp)
Hendekagon
  • 4,565
  • 2
  • 28
  • 43
1
vote
1 answer

Can I use Oracle analytical function here?

I've got this query: SELECT year, month, week, C.cpg_pk CPG, C.dep_pk DEPT, T.cust_id …
YesYeeYen
  • 55
  • 2
  • 5
1
vote
2 answers

Oracle SQL Analytics Function FirstValue with 'NULL' Values

I have an issue with the analytics function FirstValue:(Syntax: FIRST_VALUE(TAble1.Column2 IGNORE NULLS) OVER (PARTITION BY Column1 ORDER BY Column3 DESC) Example: Column1 Column2 Column3 1 A …
user1557642
  • 1,083
  • 2
  • 10
  • 6
1
vote
1 answer

Is there a way to partition a query that has a "group by" clause?

Say we I have a query that displays groups of population by country having the country as its first column, and total population of that country as its the second column. To achieve this I have the following query: select i.country, count(1)…
supertonsky
  • 2,563
  • 6
  • 38
  • 68
1
vote
1 answer

Delete a query with analytic function

Delete the records that have the minimum of records, I have 2 tables person (id, otherID) otherID is a reference of an other person.id and film (id, country, personID) where personID is a foreign key of person.id I want to delete all the records in…
R Vive L OL
  • 177
  • 3
  • 3
  • 10
0
votes
1 answer

Oracle query optimization written on table with partition

I have one table in Oracle consists of around 55 million records with partition on date column. This table stores around 600,000 records for each day based on some position. Now, some analytical functions are used in one select query in procedure…
user1017936
  • 143
  • 1
  • 5
  • 14
0
votes
2 answers

Which databases have analytic functions like Oracle

Doesn't have to be the same syntax, but same or similar functionality. Please provide the name used for the construct and a simple example.
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
0
votes
3 answers

"line fusion" in oracle

I am trying to do "line fusion" in Oracle, i.e. I want to have a query that returns lines, and each of these lines has, for each column, values that were originally stored in other lines. For instance (I am following the documentation), let's say I…
lezebulon
  • 7,607
  • 11
  • 42
  • 73
0
votes
2 answers

Fetching data only if there are multiple rows in the result

Suppose I have a table abc with columns p_id ,u_id, and comments. I want to fetch the data from this table only if there are multiple rows for a particular p_id value (there is a single row of "junk" data in the table for every p_id that I want to…
Gaurav Soni
  • 6,278
  • 9
  • 52
  • 72
0
votes
2 answers

Not able to retrieve desired data from sql query

SELECT a.alloc_date, p.plan, p.emp_id, a.veh, a.contri_type, a.amount, SUM (a.alloc_qty) AS sum_alloc_qty, -- 1000 funds distributed SUM (a.alloc_qty * a.amount) AS sum_alloc_value, …
Gaurav Soni
  • 6,278
  • 9
  • 52
  • 72
0
votes
1 answer

Reference outer context in LAG function

I would like to make next query: select ..., ( source.F1 - /* current row */ LAG(IIF(source /*current row*/.F2 = source /*lag row*/.F2, source.F1, 0), 12, source.F1) OVER (...) ) as alias from source Desired result: when row…
Anton Putau
  • 632
  • 1
  • 7
  • 31