analytic-functions

Oracle - Increment value

家住魔仙堡 提交于 2019-12-11 04:46:27
问题 I have a table holding customer invoice data. I am trying to find how many consequently months a particular transaction type is present on a customer’s invoice by creating a carryover counter. If the transaction is no longer present, the counter should reset to zero. Table: +------------+-------------+----------------+----------+ | Invoice_Id | Customer_id | Transaction_id | Sequence | +------------+-------------+----------------+----------+ | 253442 | 23334 | | 1 | | 253443 | 23334 | | 2 | |

Oracle get row where column value changed

牧云@^-^@ 提交于 2019-12-11 03:21:08
问题 Say I have a table, something like ID CCTR DATE ----- ------ ---------- 1 2C 8/1/2018 2 2C 7/2/2018 3 2C 5/4/2017 4 2B 3/2/2017 5 2B 1/1/2017 6 UC 11/23/2016 There are other fields, but I made it simple. So I create a query where i have the date in descending order. I was to return the row where there was a change in CCTR. So in this case it would return ID 4. Basically i want to find the previous value of CCTR before it changed, in this case from 2B to 2C. How do I do this? Ive tried to

Group by vs Partition by in Oracle

岁酱吖の 提交于 2019-12-09 11:47:46
问题 I am writing a query to fetch records from a Oracle warehouse. Its a simple Select Query with joins on few tables and i have few columns to be aggregated. Hence i end up using Groupby on rest of the columns. Say I am picking some 10 columns and out of which 5 is aggregate columns. so i need to group by on the other 5 columns. I can even achieve the same by not doing a Groupby and using over (paritition by) clause on the each each aggregate column i want to derive. I am not sure which is

How can I perform linear interpolation using oracle SQL?

↘锁芯ラ 提交于 2019-12-07 13:55:02
问题 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 (with id deviceid), taken at the time given in the timestamp. For example, this is bogus data, but it gives the idea: time | deviceid | value ----------------|------------|----------- 01:00:00.000 | 001 | 1.000 01:00:01.000 | 001 | 1.030 01:00:02

How can I perform linear interpolation using oracle SQL?

a 夏天 提交于 2019-12-05 19:57:03
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 (with id deviceid), taken at the time given in the timestamp. For example, this is bogus data, but it gives the idea: time | deviceid | value ----------------|------------|----------- 01:00:00.000 | 001 | 1.000 01:00:01.000 | 001 | 1.030 01:00:02.000 | 001 | 1.063 01:00:00.050 | 002 | 553.10 01:00:01.355 | 002 | 552.30 01:00:02.155 | 002 | 552.43

Apply COUNT function on a subgroup of groups

空扰寡人 提交于 2019-12-05 16:51:56
I made up this weird example trying to illustrate what I want to do (it's kind of stupid, but bear with me): Consider the following table: EMPLOYEES married , certified and religious are just boolean fields (in case of Oracle, they are of type NUMBER(1,0)). I need to come up with SQL that displays for each hire_year, count of married, certified and religious employees within the following salary categories: A SALARY > 2000 B SALARY BETWEEN 1000 AND 2000 C SALARY < 1000 Based on the above dataset, here is what I expect to get: So far, I've only come up with the following SQL: SELECT COUNT(CASE

Group by vs Partition by in Oracle

一曲冷凌霜 提交于 2019-12-03 12:44:28
I am writing a query to fetch records from a Oracle warehouse. Its a simple Select Query with joins on few tables and i have few columns to be aggregated. Hence i end up using Groupby on rest of the columns. Say I am picking some 10 columns and out of which 5 is aggregate columns. so i need to group by on the other 5 columns. I can even achieve the same by not doing a Groupby and using over (paritition by) clause on the each each aggregate column i want to derive. I am not sure which is better against a warehouse or in general. They are not the same. This will return 3 rows: select deptno,

Oracle SQL Analytic query - recursive spreadsheet-like running total

不羁岁月 提交于 2019-12-03 04:04:33
问题 I have the following data, composed of the A value, ordered by MM (month). The B column is computed as GREATEST(current value of A + previous value of B, 0) in a spreadsheet-like fashion. How can I compute B using a SQL Query? I tried using Analytic Functions, but I was unable to succeed. I know there is the Model Clause; I found a similar example, but I don't know where to begin. I am using Oracle 10g, therefore I cannot use recursive queries. Here is my test data: MM | A | B -----------+---

Oracle SQL Analytic query - recursive spreadsheet-like running total

时光总嘲笑我的痴心妄想 提交于 2019-12-02 16:24:49
I have the following data, composed of the A value, ordered by MM (month). The B column is computed as GREATEST(current value of A + previous value of B, 0) in a spreadsheet-like fashion. How can I compute B using a SQL Query? I tried using Analytic Functions, but I was unable to succeed. I know there is the Model Clause ; I found a similar example , but I don't know where to begin. I am using Oracle 10g, therefore I cannot use recursive queries. Here is my test data: MM | A | B -----------+--------+------ 2012-01-01 | 800 | 800 2012-02-01 | 1900 | 2700 2012-03-01 | 1750 | 4450 2012-04-01 |

How do I grab the “next” event when the offset is variable?

扶醉桌前 提交于 2019-12-02 07:40:54
问题 I have a table of transactions in an Oracle database. I am attempting to pull a report together for a delivery system involving a number of transaction types. The "request" type can actually be one of four sub-types ('A', 'B', 'C', and 'D' for this example), and the "delivery" type can be one of four different sub-types ('PULL', 'PICKUP', 'MAIL'). There can be anywhere from 1 to 5 transactions to get an item from "request" to "delivery, and a number of the "delivery" types are also