|
|
|
|
|
|
Re: Calculation mode need closing value as shown in image [message #660178 is a reply to message #660177] |
Fri, 10 February 2017 12:47 |
|
sr8464
Messages: 82 Registered: February 2017 Location: India
|
Member |
|
|
i have two table qtyrecd and qtyissued
suppose i have 5 records/rows
queried into form
-------- qtyrecd ---- qtyissued --- closing
---------- 1 ---------- 0 ---------- 1
---------- 2 ---------- 0 ---------- 3
---------- 0 ---------- 2 ---------- 1
---------- 0 ---------- 1 ---------- 0
---------- 3 ---------- 0 ---------- 3
------------------------------------------------------
total------ 6 ------------ 3 ------------ 3
done sum using total but totally clueless on closing
needed closing coding
looked Analytic Functions
no idea how to code this for each row
[Updated on: Fri, 10 February 2017 12:51] Report message to a moderator
|
|
|
|
|
|
|
Re: Calculation mode need closing value as shown in image [message #660190 is a reply to message #660182] |
Sat, 11 February 2017 06:36 |
shahzad-ul-hasan
Messages: 640 Registered: August 2002
|
Senior Member |
|
|
I assume you mean you want a running total. I would take this approach. I presume that you have a field defined on the block 'Running total' which is not based on a table.
Define a global variable in the when-new-form-instance trigger. In the Post-Query trigger:
Code (Text):
:global.var := :global.var + :qty-:issqty;
:run_tot := :global.var;
:qty is the field in the block which you are receiving and :issqty is issued qty. Remember to initialize :global .
Or
You can use Try the ROLLUP analytical function. ROLLUP enables a SQL statement to calculate multiple levels of subtotals across a specified group of dimensions. It also calculates a grand total. ROLLUP is a simple extension to the GROUP BY clause, so its syntax is extremely easy to use. It also only does one-pass through the table, so it's efficient too!
SELECT
deptno,
job,
count(*),
sum(sal)
FROM
emp
GROUP BY
ROLLUP(deptno,job);
DEPTNO JOB COUNT(*) SUM(SAL)
--------- --------- --------- ---------
10 CLERK 1 1300
10 MANAGER 1 2450
10 PRESIDENT 1 5000
--> 10 3 8750
20 ANALYST 2 6000
20 CLERK 2 1900
20 MANAGER 1 2975
--> 20 5 10875
Send Test case. it will be more practical.
[Updated on: Sat, 11 February 2017 06:48] Report message to a moderator
|
|
|
|
|
|
|
|
|
Re: Calculation mode need closing value as shown in image [message #660210 is a reply to message #660196] |
Sun, 12 February 2017 08:09 |
|
sr8464
Messages: 82 Registered: February 2017 Location: India
|
Member |
|
|
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.
SQL> select * from dept;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL>
SQL> select dname,
2 ename,
3 sal,
4 sum(sal) over ( partition by dname
5 order by dname, ename ) dept_running_total,
6 sum(sal) over ( order by dname, ename ) running_total
7 from emp, dept
8 where emp.deptno = dept.deptno
9 order by dname, ename
10 /
DNAME ENAME SAL DEPT_RUNNING_TOTAL RUNNING_TOTAL
-------------- ---------- ---------- ------------------ -------------
ACCOUNTING CLARK 2450 2450 2450
KING 5000 7450 7450
MILLER 1300 8750 8750
RESEARCH ADAMS 1100 1100 9850
FORD 3000 4100 12850
JONES 2975 7075 15825
SCOTT 3000 10075 18825
SMITH 800 10875 19625
SALES ALLEN 1600 1600 21225
DNAME ENAME SAL DEPT_RUNNING_TOTAL RUNNING_TOTAL
-------------- ---------- ---------- ------------------ -------------
SALES BLAKE 2850 4450 24075
JAMES 950 5400 25025
MARTIN 1250 6650 26275
TURNER 1500 8150 27775
WARD 1250 9400 29025
14 rows selected.
its only addition how i divide from another table???
[Edit MC: remove execution of SCOTT's CREATE TABLE and INSERT statements code and execution]
[Updated on: Sun, 12 February 2017 09:55] by Moderator Report message to a moderator
|
|
|
Re: Calculation mode need closing value as shown in image [message #660215 is a reply to message #660210] |
Sun, 12 February 2017 09:53 |
|
Michel Cadot
Messages: 68728 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
You don't need to post the code for Oracle standard tables (in addition it is copyrighted, so you must not).
Also a test case is just the statements WITHOUT their execution, but you must verify that the statements are correct executing at your side but NOT posting the execution listing.
In the end, use "set pages 1000" to avoid column headers repetition and post a clean listing.
Quote:ts only addition how i divide from another table???
What does this mean?
Post a test case showing what you mean.
[Updated on: Sun, 12 February 2017 09:56] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Calculation mode need closing value as shown in image [message #660313 is a reply to message #660308] |
Tue, 14 February 2017 12:49 |
|
sr8464
Messages: 82 Registered: February 2017 Location: India
|
Member |
|
|
CREATE TABLE table1(Debit NUMBER(12,3) DEFAULT 0.000,Credit NUMBER(12,3) DEFAULT 0.000);
insert into table1 (Debit, Credit) values ('1',0);
insert into table1 (Debit, Credit) values ('0',1);
insert into table1 (Debit, Credit) values ('2',0);
insert into table1 (Debit, Credit) values ('0',1);
[Updated on: Tue, 14 February 2017 12:54] Report message to a moderator
|
|
|
|
Re: Calculation mode need closing value as shown in image [message #660316 is a reply to message #660314] |
Tue, 14 February 2017 13:43 |
|
sr8464
Messages: 82 Registered: February 2017 Location: India
|
Member |
|
|
CREATE TABLE table1(Debit NUMBER(12,3) DEFAULT 0.000,Credit NUMBER(12,3) DEFAULT 0.000);
insert into table1 (Debit, Credit) values (1,0);
insert into table1 (Debit, Credit) values (0,1);
insert into table1 (Debit, Credit) values (2,0);
insert into table1 (Debit, Credit) values (0,1);
|
|
|
|
Re: Calculation mode need closing value as shown in image [message #660327 is a reply to message #660318] |
Wed, 15 February 2017 00:23 |
|
sr8464
Messages: 82 Registered: February 2017 Location: India
|
Member |
|
|
Order by vrno ascDROP TABLE TABLE1;
CREATE TABLE table1(VRNO NUMBER(5),Debit NUMBER(12,3) DEFAULT 0.000,Credit NUMBER(12,3) DEFAULT 0.000);
insert into table1 (VRNO, Debit, Credit) values (1,1,0);
insert into table1 (VRNO, Debit, Credit) values (2,0,1);
insert into table1 (VRNO, Debit, Credit) values (3,2,0);
insert into table1 (VRNO, Debit, Credit) values (4,0,1);
[Updated on: Wed, 15 February 2017 00:24] Report message to a moderator
|
|
|
|
|
|
|
|