Get the cumulative sum
HelloWhat can I do to obatain the net sum of these records
day net
------------------------------------------------
01-03-12 00:00:00 41946,4
02-03-12 00:00:00 45263,82
03-03-12 00:00:00 64980,98
04-03-12 00:00:00 42695,22
05-03-12 00:00:00 29678,96
06-03-12 00:00:00 30537,88
07-03-12 00:00:00 31348,47
08-03-12 00:00:00 50076,46
09-03-12 00:00:00 45184,64
10-03-12 00:00:00 53773,22
Thanks in advance
Tags: Database
Similar Questions
-
get the cumulative sum of the salaries of the employees of emp table
Hi gurus,
Can any body tell me how to get the cumulative sum of the salaries of the employees in the emp table using analytical functions.
Thanks in advance...Please read the document
http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/functions163.htm#sthref2186
Look for example at the bottom of the document.
-
find the cumulative sum of the previous columns
Hello
How can I get the cumulative sum of a particular column in the preceding lines in the current line.
e.g. I have a table produced,
Date | Orders
__________________
1 JANUARY 10 | 3
JANUARY 2, 10. 5
JANUARY 3, 10. 1
I want to select the date and orders between the 1st and the 3rd. Something like...
Select the Date, the orders for products where Date between to_date('1-JAN-10') and to_date('3-JAN-10')
But I want the output like this...
Date | Orders
__________________
1 JANUARY 10 | 0
JANUARY 2, 10. 3
JANUARY 3, 10. 8
Similarly, when I select it between 2 and 3, I want the output voltage...
Date | Orders
_________________
JANUARY 2, 10. 3
JANUARY 3, 10. 8
and so on. In the output, orders here are the cumulative sum of the previous columns.
Published by: eric clapton, November 8, 2010 20:45Hello
Use the analytical SUM function.
You want to filter by date after the cumulative SUM is calculated, so calculate the SUM in a subquery, then filter by date no later than:WITH got_cm_orders AS ( SELECT dt , orders , SUM (orders) OVER (ORDER BY dt) - orders AS cm_orders FROM products ) SELECT dt , orders WHERE dt BETWEEN DATE '2010-01-02' AND DATE '2010-01-03' ;
-
Get the cumulative values in a single column based on another column in reports
Hi all
I have a requirement to get cumulative values based on another column.I 'Sales rep name' in the first column.
Since there is no rank option in the PivotTable, I do this in the report table.
Correspondent "Values of the invoice line" in the second column.
Want to have cumulative of all the values for each sales invoice line.
Then apply rank and display the top 10 sales reps based on invoice lines.
Looking for the best entries...
Thanks in advance...Try below
2nd column: "name of Sales rep.
column 2: SUM ("invoice line values ' BY 'Name of Sales rep'") and sort this field desc.
3rd column: fx RANK (SUM ("invoice line values" BY "Sales rep name")), to hide this column, so that you don't confuse your users.and put the filter on the 3rd column below 5
I hope this works for you
-
Cumulative sum of 3.1 to 6 1 and 1 to 9 and 1 to 11 lines
How to get the cumulative sum of follow-up records since of 1To 3.1 to 6 and 1 to 9 and 1 to 11
A sum (AVG) AVERAGE of BEG END TEACHER
--------------------------------------------------
1 0 0.1 159 159
2 0.1 0.2 159 168
3 0.2 0.3 179 159 486 (sum of lines 1 to 3)
4 0.1 0.2 250 300
5 0.2 0.3 320 250
6 0.4 0.3 250 380 1416 (sum of lines 1 to 6)
7 0.2 0.3 388 379
8 0.3 0.4 379 388
9 388 400 2583 0.5 0.4 (sum of lines 1 through 9)
10 1.5 0.6 499 500
11 420 448 3531 0.5 0.6 (sum of lines 1 to 11)
create table TABLEAA
(
A NUMBER,
PLEASE THE NUMBER,
NUMBER OF END,
NUMBER OF TEACHER,
AVERAGE NUMBER
)
;
Fast loading TABLEAA...
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (10, 1.5,.6,, 499, 500);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (1, 0,.1, 159, 159);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (2,.1,.2,, 159, 168);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (3,.2,.3, 179, 159);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (4,.1,.2, 250, 300);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (5,.2,.3, 320, 250);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (6,.3,.4,, 250, 380);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (7,.2,.3, 388, 379);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (8,.3,.4,, 379, 388);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (9,.4,.5, 388, 400);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (11.5.6, 420, 448);
commit;SQL> select t.*, case when mod ( row_number () over (order by a), 3 ) = 0 or a = last_value (a) over () then sum (average) over (order by a) end s from tableaa t order by a / A BEG END PROF AVERAGE S ---------- ---------- ---------- ---------- ---------- ---------- 1 0 ,1 159 159 2 ,1 ,2 159 168 3 ,2 ,3 179 159 486 4 ,1 ,2 250 300 5 ,2 ,3 320 250 6 ,3 ,4 250 380 1416 7 ,2 ,3 388 379 8 ,3 ,4 379 388 9 ,4 ,5 388 400 2583 10 1,5 ,6 499 500 11 ,5 ,6 420 448 3531 11 rows selected.
-
Hello
I have generated a report, need to create the cumulative sum in my reports.can someone give me the solution how do.cummulative are like
col1 col2 col 3 (cummulative_sum)
A 5 5
B-10-15 (5 + 10)
15-30 (15 + 15) c
receive your answer.
Brgds,
GN
Published by: GN on January 31, 2012 03:48Hello
You can use ABSTRACT (Measure_Column).
Concerning
YoungNOTE - Please make this thread closed / or still facing issue so that she could help others.
-
A security update for windows vista (KB2665364) cumulative hotfix for Kiibits (KB2647518) Activex and update Windows vista ((KB2679255) I get the error codes 800736B 3 and B 8007371) I can't find answers and I'm not tech saavy. Every day for a month updates failed to install
Hello
I would suggest trying the following methods and check if it helps.
Method 1:
In the following article from Microsoft Fixit to reset Windows Update components and check if the problem persists, run the fixit.
How to reset the Windows Update components?
http://support.Microsoft.com/kb/971058
Warning: Important This section, method, or task contains steps that tell you how to modify the registry. However, serious problems can occur if you modify the registry incorrectly. Therefore, make sure that you proceed with caution. For added protection, back up the registry before you edit it. Then you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click on the number below to view the article in the Microsoft Knowledge Base: http://windows.microsoft.com/en-US/windows-vista/Back-up-the-registry
Method 2:
Put the computer in a clean boot state, and then try to install the updates and check if it works.
How to troubleshoot a problem by performing a boot in Windows Vista or Windows 7:
http://support.Microsoft.com/kb/929135
Note: once you have completed troubleshooting, try the procedure described in step 7 to reset the computer to start as usual.
Method 3:
Try to download updates from the Microsoft Downloads Web site and check.
http://www.Microsoft.com/download/en/default.aspx
Hope the information is useful.
-
Mr President.
I have to take the column values from3, or 4 tables and two of them need to be multiplied, then get the sum of this value multiplied by using Group by and order clause.
as below
cust_id prod name Qty. rate value totalValue 01 one 01 500 500 01 b 02 400 800 1300 How to get there
Select
cstmr.cust_id CustId,
PRDT. Name AutoCAD,
SL.sal_qty SalQty,
SL.unit_sal_price UnitSalPrice,
SL.sal_qty * SL.unit_sal_price as SalVal,
Sum(SL.sal_qty*SL.unit_sal_price) as TotalSalesValue
Of
cstmr customer,
salesLine sl,
prdt product
where
PRDT.prod_id = sl.prod_id
Group
cstmr.cust_id,
PRDT. Name,
SL.sal_qty,
SL.unit_sal_price
order by
cstmr.cust_id
Concerning
Your expected results include values that are not in your input data - there is no M.BOARD product, for example. This is an adaptation of Manik code that will give you the subtotals for each customer:
SELECT client_name c.nom,
product_name p.Name,
SL.sal_qty,
SL.unit_sal_price,
SL.sal_qty * SL.unit_sal_price AS salesvalue,
CASE
WHEN ROW_NUMBER () OVER (partition by order of c.cust_id p.prod_id desc, sl.sal_id desc) = 1 THEN
SUM (sl.sal_qty * sl.unit_sal_price) OVER (PARTITION BY c.cust_id)
END totals
FROM customer c INNER JOIN sales s ON s.cust_id = c.cust_id
INNER JOIN salesline sl ON sl.sal_id = s.sal_id
INNER JOIN product p ON p.prod_id = sl.prod_id
ORDER BY c.cust_id, p.prod_id, sl.sal_id
You could get the grand total of lines by the Union in a second query, or by doing something smart using ROLLUP. But I leave that to you because I think you should at least do some of your own homework.
-
try to get the SUM of all of the charges with the having clause
Hi Oracle users.
I'm trying to accomplish to get a sum of a series of charges and it should be easy, but I can't get it.
For example, I have the following.
Select ACCTLOC, count(ACCTLOC) AS TOTALP FROM BOX_ACCTS_TBL WHERE TIME_REQ > SYSDATE-120 Group By ACCTLOC having (count(ACCTLOC) > 1) the results are ACCTLOC TOTALP Philly 15970 NY 8623 Tacoma 3 SanFran 195 Hartford 5 Miami 4374
How can I get the SUM of this group? Do I put this in PL SQL and do a procedure to carry out the selection? Is this the way to go on this?
I appreciate all the comments you can give.Thank you!
with
query_result as
(select 'Philly' acctloc, 15970 totalp Union double all the)
Select "NY", 8623 Union double all the
Select "Tacoma", 3 double Union all
Select "SanFran", 195 double Union all
Select "Hartford", 5 Union double all the
Select 'Miami', double 4374
)
Select acctloc, totalp, sum (totalp) on the_sum, avg (totalp) (on the_avg), ratio_to_report (totalp) (percentages))
of query_result
ACCTLOC TOTALP THE_SUM THE_AVG PERCENTAGES Philly 15970 29170 4861.66666666666666666666666666666666667 .547480287967089475488515598217346588961 NY 8623 29170 4861.66666666666666666666666666666666667 .295611930065135413095646211861501542681 Tacoma 3 29170 4861.66666666666666666666666666666666667 .000102845389098388755570791909496057593 SanFran 195 29170 4861.66666666666666666666666666666666667 .006684950291395269112101474117243743572 Hartford 5 29170 4861.66666666666666666666666666666666667 .000171408981830647925951319849160095989 Miami 4374 29170 4861.66666666666666666666666666666666667 .149948577305450805622214604045251971203 Concerning
Etbin
-
using script to get the values of percentage and not able to sum up to 100%
Hi all
I am trying to use a parseFloat() function to convert the string value as a percentage, and then try to add all the values of %.
but for a few scenrios even if the amount is 100% of the service I get the PctValue be <>100.00%
the calculation of the function is as follows: -.
code-
{iterating_through_all_the_fields}
PctValue += parseFloat (this.getField("Percentage1").valueAsString);
}
sample-
11.12
11.11
11.11
11.11
11.11
11.11
11.11
11.11
11.11
amount is 100
but through code mentioned above I return 99.99
Any help is appreciated in this regard.
It is a result using the floating point IEEE standard and conversion from decimal to binary values values. We need to round up all the calculations of money or mils will accumulate and cause errors. For percentages, it is better to round up receipts and total final eliminate the accumulation of amounts below the figure the least significant.
It is possible to use the util.printf of rounding.
The following script will show what is happening:
function Round (nValue, nDec) {}
If (typeof nDec == "undefined") nDec = 0;
Return number (util.printf ('%, 1 0. nDec + "f", Number (nValue)));
}var nValues = new Array (11.12 11.11 11.11, 11.11, 11.11, 11.11, 11.11, 11.11, 11.11);
nSum var = 0;
for (var i = 0; i)< nvalues.length;="" i++="" )="">
nSum = nSum + Round (nValues [i], 2);
Console.println (i + "" + nValues [i] + "" + nSum);
}
Console.println (nSum);
nSum = Round (nSum, 2);
Console.println (nSum);Progression of the sum at each stage.
0 11,12 11.12
1 11.11 22.229999999999997
2 11.11 33.339999999999996
3 11.11 44.449999999999996
4 11.11 55.559999999999995
5 11.11 66.66999999999999
6 11.11 77.77999999999999
7 11.11 88.88999999999999
8 11.11 99.99999999999999
99.99999999999999
100true
It's a good idea to use decimal values a percentage and leave the determination of the field format display and the borough. But for applications of the sum, the user can round up the value of the actual field and not only display.
-
How to get the last row and the sum of all columns in a query
Hello
is there a way to get the last record for a column and the sum of all the Archives to another column in the same query.
Best regards
You must set your needs correctly volunteers to help here...
Your data are not good enough to bring you a precise solution. Purpose, you do not have a column, which draws a distinction between the first and the last entry.
The solution becomes easy based on your design.
I introduced a grouping called 'id' column and a time column called 'time_of_insert' (only this way you can say with confidence that you can differentiate between the first and last (also a foolproof solution) - you can possibly use sequence (instead of date but if you say that you can insert two lines at the same time) ((and then likely sequence would be a better choice to differentiate instead of a timestamp field) etc...)
With your sample data, something like this can be done to get the desired results.
-----------------------------------------------------------------------------------------------------------------------
WITH dataset AS
(SELECT 1 id, 10 used, 8 remain, systimestamp + 1/24 time_of_insert FROM DUAL
UNION ALL
SELECT the 1 id, 1, 7, systimestamp + 2/24 FROM DUAL
UNION ALL
SELECT the id 1, 2, 5, systimestamp + 3/24 FROM DUAL
UNION ALL
SELECT 1 id, 1, 0, systimestamp + 4/24 FROM DUAL
UNION ALL
SELECT 1 id, 0, 0, systimestamp + 5/24 FROM DUAL
UNION ALL
SELECT the 1 id, 1, 4, systimestamp + 6/24 FROM DUAL)
SELECT *.
(SELECT SUM (used) ON sum_all)
FIRST_VALUE (stay)
COURSES (PARTITION BY id ORDER BY time_of_insert DESC)
last_row
Of THE dataset)
WHERE ROWNUM = 1;
Output:
------------------------
SUM_ALL LAST_ROW
------------------------------
15 4
See you soon,.
Manik.
-
How get the sum of differences in time
I have the query to get the taken (duration) of time to perform each activity below
Select (select ep.name PE env_mapping where ep.id = p.bsa_env_id) environment,
(Select trunc ((Max (ps.actual_end) - Min (ps.actual_start)) * 24 * 60) of ps Highlevel_activity where ps.activity_ID = p.id and ps.out_of_window_flag =' no. "") Actual_duration,
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Apps Patching"and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Apps_Patching,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, Highlevel_activity ps where de.task_type = ' Patching DB/MT ' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') DB_MT_Patching,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Shut Down' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Shut_Down,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Start Up' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Start_Up,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Vérification' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = 'NO') audit.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Patching meadow' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Pre_Patching,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Patching Post' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Post_Patching,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Others' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = 'NO') others
activity p where
I get the output as below
EnV1 27 April 13 167 54 29 29 15 0 0 67 0
EnV2 may 3 13 10 20 05 05 0 0 50 0 33
My requirement is to get the amount for each column which I get on top of the query. How can I change the query above to get as the result below
EnV1 27 April 13 167 54 29 29 15 0 0 67 0
EnV2 may 3 13 10 20 05 05 0 0 50 0 33
177 74 34 34 15 50 67 33 total
Please help
Thank you
ArchanaHello
Agowda wrote:
I have the query to get the taken (duration) of time to perform each activity belowSelect (select ep.name PE env_mapping where ep.id = p.bsa_env_id) environment,
(Select trunc ((Max (ps.actual_end) - Min (ps.actual_start)) * 24 * 60) of ps Highlevel_activity where ps.activity_ID = p.id and ps.out_of_window_flag =' no. "") Actual_duration,
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Apps Patching"and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Apps_Patching,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, Highlevel_activity ps where de.task_type = ' Patching DB/MT ' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') DB_MT_Patching,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Shut Down' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Shut_Down,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Start Up' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Start_Up,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Vérification' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = 'NO') audit.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Patching meadow' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Pre_Patching,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Patching Post' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Post_Patching,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Others' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = 'NO') othersactivity p where
If you make 9 of subqueries to get 9 different columns. It is very inefficient, and it is also difficult to maintain. If you need to change the conditions in subqueries, you will need to do the exact same change at 9 different locations.
It would be much more effective if you just add de.task_type to the GROUP BY clause and then rotates the results. He could not run 9 times faster, but it probably run 5 times faster.
See the FAQ forum {message identifier: = 9360005} to find out how.I get the output as below
EnV1 27 April 13 167 54 29 29 15 0 0 67 0
EnV2 may 3 13 10 20 05 05 0 0 50 0 33My requirement is to get the amount for each column which I get on top of the query. How can I change the query above to get as the result below
EnV1 27 April 13 167 54 29 29 15 0 0 67 0
EnV2 may 3 13 10 20 05 05 0 0 50 0 33
177 74 34 34 15 50 67 33 totalIt's a GROUPING DEFINED work, no ACCUMULATION.
Since you post CREATE TABLE and INSERT statemennts for your sample data, I will use the hr.departments table to show the difference.
When you GROUP BY N > 1 the expressions, ROLLUP gives you N + 1 levels of totals and subtotals. For example:SELECT department_id , job_id , SUM (salary) AS total_sal FROM hr.employees GROUP BY ROLLUP (department_id, job_id) ORDER BY department_id, job_id ;
The above query GROUPs BY s expressions (department_id job_id) so ROLLUP produces 3 sorts of totals:
(1) total department_id and job_id (e.g. 13000 for department_id = 20 and job_id = "Fatyty" below)
(2) total Department, including all of the work (e.g. 6000 = 19000 13000 + for department_id = 20) and
(3) total general for the entire result (e.g. 691416)DEPARTMENT_ID JOB_ID TOTAL_SAL ------------- ---------- ---------- 10 AD_ASST 4400 10 4400 20 MK_MAN 13000 20 MK_REP 6000 20 19000 30 PU_CLERK 13900 30 PU_MAN 11000 30 24900 40 HR_REP 6500 40 6500 50 SH_CLERK 64300 50 ST_CLERK 55700 50 ST_MAN 36400 50 156400 60 IT_PROG 28800 60 28800 70 PR_REP 10000 70 10000 80 SA_MAN 61000 80 SA_REP 243500 80 304500 90 AD_PRES 24000 90 AD_VP 34000 90 58000 100 FI_ACCOUNT 39600 100 FI_MGR 12008 100 51608 110 AC_ACCOUNT 8300 110 AC_MGR 12008 110 20308 SA_REP 7000 7000 691416
You don't want all that: you just want what corresponds in total for each department_id and job_id and total general, without any level of iintermediate. Here's how you can achieve these results using GROUPING SETS instead of ROLLUP:
SELECT department_id , job_id , SUM (salary) AS total_sal FROM hr.employees GROUP BY GROUPING SETS ( (department_id, job_id) , () ) ORDER BY department_id, job_id ;
DEPARTMENT_ID JOB_ID TOTAL_SAL ------------- ---------- ---------- 10 AD_ASST 4400 20 MK_MAN 13000 20 MK_REP 6000 30 PU_CLERK 13900 30 PU_MAN 11000 40 HR_REP 6500 50 SH_CLERK 64300 50 ST_CLERK 55700 50 ST_MAN 36400 60 IT_PROG 28800 70 PR_REP 10000 80 SA_MAN 61000 80 SA_REP 243500 90 AD_PRES 24000 90 AD_VP 34000 100 FI_ACCOUNT 39600 100 FI_MGR 12008 110 AC_ACCOUNT 8300 110 AC_MGR 12008 SA_REP 7000 691416
I hope that answers your question.
If this isn't the case, post CREATE TABLE and INSERT statements for some examples of data and the results desired from these data.
Simplify the problem. For example, instead of 9 different task_types, post sample data and results for 3 task_types. Simply mention that you actually 9, and we will find a solution that can be easily adapted for 9.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum {message identifier: = 9360002}Published by: Frank Kulash on May 27, 2013 10:47
-
to get the sum of the balance_due
Hi all
I have this request with meSELECT rac.customer_number, rac.customer_name, su.LOCATION contract, SUBSTR (sa.NAME, 1, 2) bu, ra.purchase_order_date sub_date, ra.invoice_currency_code ccy,RA.PURCHASE_ORDER,ra.trx_number, TRUNC (rad.gl_date) gl_date, SUM (npar_get_invoice_balance (ra.customer_trx_id, '08-Sep-2011' ) ) balance_due FROM ra_customer_trx_all ra, ra_site_uses_all su, ra_cust_trx_line_gl_dist_all rad, ra_customers rac, ra_cust_trx_types_all ty, ra_salesreps_all sa WHERE TRUNC (rad.gl_date) <= '08-Sep-2011' AND ra.bill_to_customer_id = rac.customer_id AND su.site_use_code = 'BILL_TO' AND su.site_use_id = ra.bill_to_site_use_id AND ty.cust_trx_type_id = ra.cust_trx_type_id AND ty.TYPE = 'INV' AND ty.org_id <> -3113 AND rad.customer_trx_id = ra.customer_trx_id AND rad.account_class = 'REC' AND rad.latest_rec_flag = 'Y' AND npar_get_invoice_balance (ra.customer_trx_id, '08-Sep-2011') <> 0 AND sa.salesrep_id(+) = ra.primary_salesrep_id AND sa.org_id(+) <> -3113 and ra.purchase_order='2011-0526' GROUP BY rac.customer_number, rac.customer_name, su.LOCATION, ra.invoice_currency_code , ra.trx_number, RA.PURCHASE_ORDER, rad.gl_date, ra.purchase_order_date, ra.invoice_currency_code, SUBSTR (sa.NAME, 1, 2) with the following output CUSTOMER_NUMBER CUSTOMER_NAME CONTRACT BU SUB_DATE CCY PURCHASE_ORDER TRX_NUMBER GL_DATE BALANCE_DUE 1002 Joint Operations (KGOC / SAC) JO/SA88/WO06 12 05/29/2011 KWD 2011-0526 2011-0526-M 05/23/2011 4,773.60 1002 Joint Operations (KGOC / SAC) JO/SA88/WO06 12 05/29/2011 KWD 2011-0526 2011-0526-S 05/23/2011 3,559.78
Inorder to get this output I have to avoid the group clause trx number and then only to get the sum of the 8333.38, but I need trx number too in my query.i require the following output CUSTOMER_NUMBER CUSTOMER_NAME CONTRACT BU SUB_DATE CCY PURCHASE_ORDER TRX_NUMBER GL_DATE BALANCE_DUE 1002 Joint Operations (KGOC / SAC) JO/SA88/WO06 12 05/29/2011 KWD 2011-0526 2011-0526-M 05/23/2011 8333.38 1002 Joint Operations (KGOC / SAC) JO/SA88/WO06 12 05/29/2011 KWD 2011-0526 2011-0526-S 05/23/2011 8333.38 ie balance due is sum of the balances of trx numbers 2011-0526-M and 2011-0526-S(4733.60+ 3559.78)
Can this be achieved
kindly help
thanking in advanceSomething like:
SELECT rac.customer_number, rac.customer_name, su.LOCATION contract, SUBSTR (sa.NAME, 1, 2) bu, ra.purchase_order_date sub_date, ra.invoice_currency_code ccy,RA.PURCHASE_ORDER,ra.trx_number, TRUNC (rad.gl_date) gl_date, SUM( SUM(npar_get_invoice_balance( ra.customer_trx_id, '08-Sep-2011' ) ) OVER( PARTITION BY rac.customer_number, rac.customer_name, su.LOCATION, ra.invoice_currency_code , RA.PURCHASE_ORDER, TRUNC (rad.gl_date), ra.purchase_order_date, ra.invoice_currency_code, SUBSTR (sa.NAME, 1, 2) ) ) balance_due FROM ra_customer_trx_all ra, ra_site_uses_all su, ra_cust_trx_line_gl_dist_all rad, ra_customers rac, ra_cust_trx_types_all ty, ra_salesreps_all sa WHERE TRUNC (rad.gl_date) <= '08-Sep-2011' AND ra.bill_to_customer_id = rac.customer_id AND su.site_use_code = 'BILL_TO' AND su.site_use_id = ra.bill_to_site_use_id AND ty.cust_trx_type_id = ra.cust_trx_type_id AND ty.TYPE = 'INV' AND ty.org_id <> -3113 AND rad.customer_trx_id = ra.customer_trx_id AND rad.account_class = 'REC' AND rad.latest_rec_flag = 'Y' AND npar_get_invoice_balance (ra.customer_trx_id, '08-Sep-2011') 0 AND sa.salesrep_id(+) = ra.primary_salesrep_id AND sa.org_id(+) -3113 and ra.purchase_order='2011-0526' GROUP BY rac.customer_number, rac.customer_name, su.LOCATION, ra.invoice_currency_code , ra.trx_number, RA.PURCHASE_ORDER, rad.gl_date, ra.purchase_order_date, ra.invoice_currency_code, SUBSTR (sa.NAME, 1, 2) /
SY.
-
How to get the sum of the first row in the previous row?
Dear gurus... I need to get the sum of a column of the first row of my result set to the previous line based on a condition. I read analytical functions for this but they provide the sum of the first rank to Current Row through declaration "rows between Unbounded preceding and current line. Y at - it a statement that calculates the sum as "rows between Unbounded preceding and previous row?Hello
kamranpathan wrote:
Dear gurus... I need to get the sum of a column of the first row of my result set to the previous line based on a condition. I read analytical functions for this but they provide the sum of the first rank to Current Row through declaration "rows between Unbounded preceding and current line.If you do not explicitly give a windowing clause, then you get the default windowing clause you indicated.
If you want another clause of windowing, ionclude in the analytic function call.Y at - it a statement that calculates the sum as "rows between Unbounded preceding and previous row?
Yes. The correct syntax for "Previous rank" is «PREVIOUS 1»
... ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING
For more information, search for "Analytic Functions" in the manual of the SQL language:
http://download.Oracle.com/docs/CD/E11882_01/server.112/e17118/functions004.htm#sthref917I hope that answers your question.
If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all tables and also post the results desired from these data.
Explain, using specific examples, how you get these results from these data.
Always tell what version of Oracle you are using.
You will find the answers better faster if you always provide this information whenever you post a question.Published by: Frank Kulash, Sep 17, 2011 17:04
I just saw Etbin responses.
As usual, Etbin has a good point. If the column that you are basically cannot be NULL, then it is probably easier to subtract the total current line and use the default windowing clause.
Even if it can be null, you find may be easier to use this approach. -
get the value of sum of days between
can someone please suggest me the best way to get the result.
I got the output through this approach, but because he was such a big table I don't know what is my approach
Group of Tin
o/p requiredWITH t AS (SELECT '3480154' tin, TO_DATE ('7/1/2009', 'mm/dd/yyyy') hold_begin_date, TO_DATE ('7/2/2009', 'mm/dd/yyyy') hold_end_date FROM DUAL UNION ALL SELECT '3480154' tin, TO_DATE ('7/4/2009', 'mm/dd/yyyy') hold_begin_date, TO_DATE ('7/10/2009', 'mm/dd/yyyy') hold_end_date FROM DUAL UNION ALL SELECT '3480154' tin, TO_DATE ('7/10/2009', 'mm/dd/yyyy') hold_begin_date, TO_DATE ('7/11/2009', 'mm/dd/yyyy') hold_end_date FROM DUAL UNION ALL SELECT '3480154' tin, TO_DATE ('7/12/2009', 'mm/dd/yyyy') hold_begin_date, TO_DATE ('7/14/2009', 'mm/dd/yyyy') hold_end_date FROM DUAL) SELECT tin, hold_begin_date, hold_end_date, (hold_end_date - hold_begin_date) hcus, (SELECT 18 - SUM (hold_end_date - hold_begin_date) FROM t) FROM t;
TIN Hold start date end Hold HCU/Stop Clock(hold_begin-hold_end) real Days (18 - sum (HCUS))
3480154 7/1/2009 7/2/2009 1-8
3480154 7/4/2009 7/10/2009 6-8
3480154 7/10 / 2009 2009-11-7 1 8
3480154 7/12 / 2009 7/14/2009 2 8
Published by: DeepakDevarapalli on October 23, 2009 08:18
Published by: DeepakDevarapalli on October 23, 2009 08:23You can use an analytic function:
WITH t AS (SELECT '3480154' tin, TO_DATE ('7/1/2009', 'mm/dd/yyyy') hold_begin_date, TO_DATE ('7/2/2009', 'mm/dd/yyyy') hold_end_date FROM DUAL UNION ALL SELECT '3480154' tin, TO_DATE ('7/4/2009', 'mm/dd/yyyy') hold_begin_date, TO_DATE ('7/10/2009', 'mm/dd/yyyy') hold_end_date FROM DUAL UNION ALL SELECT '3480154' tin, TO_DATE ('7/10/2009', 'mm/dd/yyyy') hold_begin_date, TO_DATE ('7/11/2009', 'mm/dd/yyyy') hold_end_date FROM DUAL UNION ALL SELECT '3480154' tin, TO_DATE ('7/12/2009', 'mm/dd/yyyy') hold_begin_date, TO_DATE ('7/14/2009', 'mm/dd/yyyy') hold_end_date FROM DUAL) SELECT tin, hold_begin_date, hold_end_date, (hold_end_date - hold_begin_date) hcus, 18 - sum(hold_end_date - hold_begin_date) over () FROM t /
Maybe you are looking for
-
Inadvertently, I deleted Firefox and emptied the Recycle Bin. I think that it is version 3.5. I have a MAC OSX 10.4.11. After several vain attempts how can I re - install the latest compatible version of Firefox on my MAC system? Thank you!
-
HP Pro slate 12: BBC IPlayer and BT Sport does not
Several applications of video streaming does not work on my new 12.Examples Pro slate are BBC IPlayer and BT Sport. When the video starts, the screen will Dim with BT SPORT and BBC IPlayer, you get a selection of error codes General referring to chec
-
Administrator account on the network
an administrator on my network can compromise my computer?
-
When information is requested I get unmarked black boxes and no way of knowing what goes where? This includes windows help and support, then others like Amazon.
-
HP Officejet 4622: Printer HP Officejet 4622 cannot read alignment page
I use a HP Officejet 4622. It ceased to print correctly. I've cleaned and tried to align the heads, but the impression seems to be so vague that the printer cannot read the alingment sheet when I try to scan to complete the process. Is that what I ca