SQL & PL/SQL :: Last 3 Receipts Based On Cumulative Balance?
Mar 19, 2011
I have one table where the item stock balance can be taken.What i want is like a ageing report based on the ending balance.If the ending balance is 10,000 for item a.It should bring all the Receipts which have qty lesser than 10,000.
I managed to write one function like below to get the receipts numbers but the format is 3778578-3778612-3790428 and i want to convert them into rows like
3778578
3778612
3790428
The function used is as below.
CREATE OR REPLACE FUNCTION l_get_rcpt (
l_item IN VARCHAR2,
l_date DATE,
l_bal IN NUMBER
)
[code]...
View 1 Replies
ADVERTISEMENT
Mar 24, 2013
Is there a way to find running balance for accounts, suppose i have two tables.one for transaction and one summary of balance.
i want to have the closing balance based on transactions subtracted or added based on credit and debit for example.it will add to the running total if its debit and subtract if its credit and final output is the balance.
create table acnt_trans ( acnt_code varchar2(12),trans_date date,debit_amt number,credit_amt number);
insert into acnt_trans values ('1001','02-FEB-2013',200,0);
insert into acnt_trans values ('1001','03-FEB-2013',0,100);
insert into acnt_trans values ('1001','04-FEB-2013',50,0);
[code]....
--I want the output as below.if i run the report as of '04-feb-2013'
trans_date , acnt_code , debit_amt,credit_amt , balance
02-feb-2013 1001 200 0 3200
03-feb-2013 1001 0 100 3100
04-feb-2013 1001 50 0 3150 -- this is the closing balance.
View 4 Replies
View Related
Jun 25, 2013
I need to get the sum of next 5 rows that are order by one specific column .
Ex :
DROP TABLE TEST_5;
CREATE TABLE TEST_5 AS
SELECT TO_NUMBER(200 || ROWNUM) YEAR, ROWNUM TOT
FROM ALL_OBJECTS
WHERE ROWNUM < = 15 ;
SQL> select * from test_5 order by year;
YEAR TOT
---------- ----------
2001 1
2002 2
2003 3
2004 4
2005 5
2006 6
2007 7
2008 8
2009 9
20010 10
20011 11
20012 12
20013 13
20014 14
20015 15
15 rows selected
SQL>
Now Expected Results :
SQL> select * from test_5;
YEAR TOT Exp_res
---------- -----------------------
2001 1 1+2+3+4+5 = 15
2002 2 2+3+4+5+6 = 20
2003 3 3+4+5+6+7 = 25
2004 4
2005 5
2006 6
2007 7
2008 8
2009 9
20010 10 10+11+12+13+14
20011 11 11+12+13+14+15
20012 12 12+13+14+15
20013 13 13+14+15
20014 14 14+15
20015 15 15
15 rows selected
SQL>
View 4 Replies
View Related
Jul 3, 2010
how to find cumulative total means i need total amount between april to sysdate.
View 1 Replies
View Related
Jun 28, 2013
Is it possible to get cumulative sum of the same column? I am trying to get a value for COL6... it is dependent on the values of previous row
COL6 Formula:
IF COL2 = 'A' THEN
IF 100 - [SUM_COL6] > COL5 THEN
COL5
ELSE
(TRUNC(100 - [SUM_COL6] / COL4) )* COL4
END IF
[code]....
View 6 Replies
View Related
Feb 24, 2011
Is it possible to calculate cumulatively in oracle sql queries, i.e. using the results of the last row for calculating the values in the current row?For example I want my query to return the following:
Month col1 _ col2 _ col3
jan 1 _ 100 _ 100 * 1
feb 2 _ 200 _ 100 * 2 + 200
mar 3 _ 300 _ 400 * 3 + 300
apr 4 _ 400 _ 1500 * 4 + 400
may 5 _ 500 _ 6400 * 5 + 500
In col3 above, for feb I want to use the result returned for jan ((100 * 1)*2+200), for mar I am using the result returned for feb((100 * 2 + 200) * 3 + 300) and so on.
i.e. I want to use the previous value of column3 to derive the current value of column3. Like using the LAG function but on the analytically derived column itself.
View 16 Replies
View Related
Mar 27, 2012
i have a table empl which have three column (name,period,attendance)if we pass parameter which value is based on period column
like :January
then out should come sum of all attendence of january group by name like that
name attendance
a60.00
b20.00
c20.00
w40.00
if we pass parameter value :February then attendance should come sum of (January and February) and if we pass parameter March then attendance should come sum of(January,February and march)
create table empl (name varchar2(10),period varchar2(10),attendance number)
insert into empl values('a','January',20)
insert into empl values('a','January',10)
insert into empl values('a','January',30)
insert into empl values('a','February',20)
insert into empl values('a','March',60)
insert into empl values('b','January',20)
insert into empl values('c','January',20)
insert into empl values('w','January',40)
View 22 Replies
View Related
Nov 29, 2012
i want to get balanced amount based on max(suid ).
my query is
create or replace procedure prc_stk_upd_pur(v_comp_suid in i_purchase_h.pih_company_suid%type,
v_area_suid in i_purchase_h.pih_area_suid%type,
v_invoice_dt in i_purchase_h.pih_invoice_date%type,
v_pih_suid in i_purchase_h.pih_suid%type,
v_type in i_purchase_h.pih_type%type) is
[code]......
my output is
SEFF_SUIDSEFF_INV_DATESEFF_LOT_SUIDSEFF_LOC_SUIDSEFF_TRAN_SUIDSEFF_TRAN_TYPESEFF_COMP_SUIDSEFF_AREA_SUIDSEFF_STOCK_INSEFF_STOCK_OUTSEFF_CURRENT_STOCKCREATE_USERCREATE_TIMESEFF_RATE_USDSEFF_RATE_LCURNSEFF_PID_SUID
1121411/29/20121317151346LP11115720.00020.000SYSTEM29-NOV-12 06.53.45.000000 PM116.14107665.30601382
2121511/29/20121317151346LP11115755.00055.000SYSTEM29-NOV-12 06.53.45.000000 PM116.14097665.30001383
3121611/29/20121317151346LP11115730.00030.000SYSTEM29-NOV-12 06.53.45.000000 PM0.440729.08401384
my output should come
SEFF_SUIDSEFF_INV_DATESEFF_LOT_SUIDSEFF_LOC_SUIDSEFF_TRAN_SUIDSEFF_TRAN_TYPESEFF_COMP_SUIDSEFF_AREA_SUIDSEFF_STOCK_INSEFF_STOCK_OUTSEFF_CURRENT_STOCKCREATE_USERCREATE_TIMESEFF_RATE_USDSEFF_RATE_LCURNSEFF_PID_SUID
1121411/29/20121317151346LP11115720.00020.000SYSTEM29-NOV-12 06.53.45.000000 PM116.14107665.30601382
2121511/29/20121317151346LP11115755.00075.000SYSTEM29-NOV-12 06.53.45.000000 PM116.14097665.30001383
3121611/29/20121317151346LP11115730.000105.000SYSTEM29-NOV-12 06.53.45.000000 PM0.440729.08401384
View 3 Replies
View Related
Sep 3, 2010
My problem is that I am working with a balance (Infor/WorkBrain - Time & Attendance) I have a balance called Bank Holiday(bal_id 10044). Every holiday that an employee works, he is allowed to take another day off in lieu of the day he worked. The employee has up to twelve months to take that holiday.
My job is to figure out when he worked that holiday (not a problem) and send an email/note at the 11 month mark and notify the employee and supervisors that said employee has 1 month to use his banked holiday.
Here is what the employee_balance log looks like.
EBLOG_IDEMP_IDBAL_IDEBLOG_DELTAWRKS_WORK_DATEWRKS_IDEBLOG_MESSAGE
51200128537100441 10/15/2010 5281229TCODE_NAME:FR_HWS
51150828537100441 7/1/2010 5136881TCODE_NAME:FR_HWS
51150928537100441 7/27/2010 5136942TCODE_NAME:FR_HWS
51150528537100441 8/1/2010 5137137TCODE_NAME:FR_HWS
5294372853710044-1 8/31/2010 5137173TCODE_NAME:FR_HWO
52947828537100441 6/3/2010 5001014TCODE_NAME:FR_HWS
My problem is the data/constraints I am working with. I can tell what day the holiday was based on a time code (EBLOG_MESSAGE) and EBLOG_DELTA shows a positive 1. I can also tell when the employee has used a bank holiday (EBLOG_DELTA is -1) and EBLOG_MESSAGE = FR_HWO.
But how to I perform the deduction so that I get four most current dates. Meaning since my first date that the employee gets for a holiday wokred is 6/3/2010 but the employee used a bank holiday on 8/31/2010. So I want to display the dates 7/1/2010, 7/27/2010, 8/1/2010 and 10/15/2010.
My preference would be not to add anything new to this table as it is a core table for Infor/WorkBrain.
View 2 Replies
View Related
May 9, 2012
I want to generate the gapless montly running balance for the whole year.Data in the table "A" is as below.
code Date amount remarks
0101 30-SEP-10 1000 Opening
0101 01-OCT-10 1500
0102 25-OCT-10 500
0102 10-DEC-10 750
0101 26-JAN-11 450
0102 03-MAR-11 3000
0101 30-SEP-11 6000
Required output is
Code Date amount Balance
0101 31-OCT-10 1500 2500
0101 30-NOV-10 0 2500
0101 31-DEC-10 0 2500
0101 31-JAN-11 450 2950
-- -- -- continue
0101 30-SEP-11 6000 8950
Same output for code 0102. I have taken only 02 code for excample only. There are about 250 code in table.
View 14 Replies
View Related
Mar 18, 2013
I have schedule table like below format:Materila Code Schedule No. Schdule Quanity Balance Quantity
ABC 1 500 500
ABC 2 300 300
ABC 3 200 200
If i received 600 quantity then data should update as below in schedule table:
ABC 1 500 0
ABC 2 300 200
ABC 3 200 200
Single material contain multiple schedules. how to programatically do the above updation.
View 15 Replies
View Related
Jan 22, 2013
I am having a table with 5 lakhs transactions. I want to fetch the last balance for a particular date. So i have have returned a query like below.
SELECT curr_balance
FROM transaction_details
WHERE acct_num = '10'
[Code]...
This has to be executed for incrementing of 12 months to find the last balance for each particular month. But this query is having more cpu cost, 12 times it is taking huge time. how to remodify athe above query to get the results in faster way using analytical query. Whether this can be broken into two part in PL/SQL to achive the performance. ?
View 9 Replies
View Related
Nov 26, 2012
I am doing a report to show current balance, aging (30-60), (60-90), (90-120) and 120+ and a combination of all of these should be the total balance overdue.
If i use a formula cclumn in the report builder, how should i write this query to calculate the total?
View 1 Replies
View Related
Apr 18, 2013
If the ASM Re balance occur automatically. What events can cause the ASM Re balance to be triggered?
I understand, we can manually re balance the disks in a disk group. I would like to know when this will happen automatically.
View 2 Replies
View Related
Aug 24, 2012
I need to calcuate balance for last two cooprative years on input date.
example
if input date is-->"01-AUG-2012" if (month >=7) -->then i need to calculate from 01-july-2010 to 30-june-2011 and 01-july-2011 to 30-june-2012 and 01-july-2012 to input date.
if input date is-->"01-june-2012" if (month<7) -->then i need to calculate from 01-july-2009 to 30-june-2010 and 01-july-2010 to 30-june-2011 and 01-july-2011 to input date.
how to achieve this logic
View 4 Replies
View Related
Nov 27, 2012
Background: We are migrating a lot of databases from one SAN appliance to another. We are doing this by adding new disks from the new SAN appliance to the existing disk groups, re balancing, removing the old disks from the disk groups, and then re balancing again.
Question: If I execute two ALTER commands with the same power on 2 or more separate disk groups, do both operations start executing right away? Or do they queue up and execute one after another?
I ask because we would like to queue up several re-balances so we don't have DBAs watching status bars all day.
View 7 Replies
View Related
May 10, 2013
Suppose I have the following, what is the best way to select the whole row that has the highest (IDX+LEN desc, LEN desc)
IDIDXLEN
5109153
7273118
9165356
I currently have made the following two method, which work but I don't particularly care for.
WITH bob AS
(SELECT 9165 id, 35 idx, 6 len FROM DUAL
UNION
SELECT 5109 id, 15 idx, 3 len FROM DUAL
UNION
SELECT 7273 id, 11 idx, 8 len FROM DUAL)
[code]....
View 3 Replies
View Related
Mar 3, 2011
How to get the max row based on a value in a column
View 1 Replies
View Related
Aug 31, 2012
One of our DB server is high on CPU utilization, as per the AWR we found couple of queries are running many times and taking huge CPU, hence we need to know from which user these queries are runnings.find the session information as per the sql id?
View 9 Replies
View Related
Nov 26, 2012
I have the following table and data , I have six employees and carton named A,B,C,D,E and F.
Drop table a ;
Create table a (id number(9), emp_id number(9), cartoon varchar2(20), no_cartton number(9));
Insert into a values(1,1,’A’,10);
Insert into a values(2,1,’B’,20);
Insert into a values(3,1,’D’,25);
Insert into a values(4,1,’E’,15);
[code].......
I have also Third Query: the first and second query already solved in this link . Sum based on group
it is multiple value of carton A of emp_id 1 with 2 + multiple value of B of emp_id 1 and 2 and so on
More detalies : Multiple value of A for Empid 1 and 2 then add it to multiple value of multiple value of b for empid 1 and 2 then add it to multiple value of c of empid 1 and 2
After finished all carton for 1 and 2 then go to 1 and 3 after finished go to 1 and 4 then 2 and 3 then 2 and 4 and so on
Output will be like this
Empid Total
1 with 2 2050
1 with 3 200
1 with 4 500
1 with 5 2250
1 with 6 700
2 with 3 0
2 with 4 700
2 with 5 4300
2 with 6 1700
3 with 4 0
3 with 5 400
3 with 6 0
4 with 5 400
4 with 6 200
5 with 6 1900
View 2 Replies
View Related
Jul 24, 2007
Is it possible to decode based off a different column? I have a status column that i want to change the value of with a decode, but only if my date column has been populated.
So if status has a value of "New" and my date column is null, then i want it to stay new. If it is populated, i want my status to change to "released"
View 5 Replies
View Related
Oct 7, 2012
I have a classification based on age and nationality to calculate if the people will reach legal age after one month . I have the peoples age , the legal age of people is 18 years .
I need to know how many people will reach this age after 1 month.
View 6 Replies
View Related
Apr 19, 2010
I want to display Week No as the heading.So, I have these:
define week_no=number
column week_col new_value week_no
select to_number(to_char(sysdate, 'ww')) week_col from dual;
I have tested it and it is working as the way I expected: select 'to display week no as column' "Week &week_no" from dual;
The output:
Week 16
----------------------------
to display week no as column ...So how do I display Week 15, Week 17 etc based on the calculation of &week_no e.g. &week_no+1?
View 19 Replies
View Related
Oct 9, 2013
I have a range date partition table month wise which i want to truncate the partition and load for each month data i get from source.
How can i get the partion name based on data value.
e.g
source data
SALES_IDSALES_DT
101/02/2008
101/03/2008
101/04/2008
101/05/2008
target table has same structure as source but has more data but i want to delete only those which is coming from source if it is there in target and then load. so i want to get partition name so that i can truncate and load them.
View 11 Replies
View Related
Mar 29, 2012
I have noticed a very questionable phrase on an article updated in 2011: "Oracle SE may allow you to create a function-based index, but you must pay for an EE license to use FBI's." [URL] Is this true? I have tested a FBI on my SE and works just fine.
Connected to:
Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
SQL> create table t ( col varchar2(10));
Table created.
SQL> create index t_idx on t(upper(col));
Index created.
SQL> insert into t values('a');
[code]....
View 11 Replies
View Related
Aug 30, 2011
how to use different where caluse based on different in parameter. say I pass 1,2 as parameter if it is 1 then the where condition > 10 else if it is 2 then the where condition <5 the where conditions are placed in cursor for loops.
View 2 Replies
View Related
Sep 24, 2010
I have this record set coming from two tables.
cursor c1 is select cust_id from tab1 where login=in_login
union
select cust_id from tab2 where login_id = in_login;
in second step; I need to process and filter these ids based on some conditions.The final filtered record set I need to return as Out cursor;
How can I use the processed data to built the output ref cursor ?
View 4 Replies
View Related
Apr 11, 2011
I would like to know, how to:
1) search for a given value in a row, and
2)in that row, identify the name of the column that contains the value
Search scope is only a single row.
View 7 Replies
View Related
Dec 1, 2011
I have a table with Column A, B, C. I want to write a query to retrieve the top row of A, B combination. i.e, for every unique value of A,B combination I want the row having highest value for C. I tried using rank() function but am not able to get the top row with combination of A,B.
View 8 Replies
View Related
Aug 4, 2013
i have a table where there are codes of length 6 or length 12 some times, i need to add the summary of amount based on two different types of codes, one is adding the distinct codes which are of 6 char long and other sum will be based on from substr(7) till last.
create table strings ( strings_var varchar2(12),strings_amt number);
insert into strings (strings_var,strings_amt) values ('02.01',10 );
insert into strings (strings_var,strings_amt) values ('02.01_A11111',15);
insert into strings (strings_var,strings_amt) values ('02.02_A11111',15);
insert into strings (strings_var,strings_amt) values ('03.01_B11111',15);
insert into strings (strings_var,strings_amt) values ('03.02_B11111',15);
the output which i want is as below.
string value
'02.01' 10
'A11111' 30
'B11111' 30
View 4 Replies
View Related