CrystalizeCanada
Instructor
Hi,
I’m struggling with a Running Total problem.
I’m attempting to create a view so I’m typing a PL-SQL statement that I think requires the use of ‘Oracle Analytics functions’ like Sum() Over and/or maybe even Lag () Over?.
It can't be a stored procedure - the result needs to be a view so I will need to put CREATE VIEW MyView ...before the statement and make it a view when I'm ready.
MY EXAMPLE
I’m given an Allowance throughout the week.
It happens to be 10 dollars but it can vary from day to day.
I can create a running total with SUM(Amt) Over etc...
This is the CUMUL column in the example below.
On certain days I’ve spent different percentages of the allowance. (The SPENT Column which is a field in the database)
I can't manage to create the AMTLEFT column in the example below.
The AmtLeft column seems to be a kind of running total that 'refers to itself' so this is where I'm stumped.
Week,Day,Amt,Cumul,Spent,AmtLeft
1,Mon,10,10,0%,10
1,Tue,10,20,50%,10
1,Wed,10,30,0%,20
1,Thu,10,40,0%,30
1,Fri,10,50,20%,32
1,Sat,10,60,0%,42
--------------------
2,Mon,10,10,00%,10
2,Tue,10,20,00%,20
etc...
My imaginary SQL would look something like at this point (if I have it right):
SELECT Week, Day, Amt, Sum(Amt) Over (Partition By Week, Order By Day) AS Cumul, Spent FROM AllowancesTable
How to get the last column AmtLeft?
Any help would be greatly appreciated...
Thanks
Gordon
Gordon BOCP
Crystalize
I’m struggling with a Running Total problem.
I’m attempting to create a view so I’m typing a PL-SQL statement that I think requires the use of ‘Oracle Analytics functions’ like Sum() Over and/or maybe even Lag () Over?.
It can't be a stored procedure - the result needs to be a view so I will need to put CREATE VIEW MyView ...before the statement and make it a view when I'm ready.
MY EXAMPLE
I’m given an Allowance throughout the week.
It happens to be 10 dollars but it can vary from day to day.
I can create a running total with SUM(Amt) Over etc...
This is the CUMUL column in the example below.
On certain days I’ve spent different percentages of the allowance. (The SPENT Column which is a field in the database)
I can't manage to create the AMTLEFT column in the example below.
The AmtLeft column seems to be a kind of running total that 'refers to itself' so this is where I'm stumped.
Week,Day,Amt,Cumul,Spent,AmtLeft
1,Mon,10,10,0%,10
1,Tue,10,20,50%,10
1,Wed,10,30,0%,20
1,Thu,10,40,0%,30
1,Fri,10,50,20%,32
1,Sat,10,60,0%,42
--------------------
2,Mon,10,10,00%,10
2,Tue,10,20,00%,20
etc...
My imaginary SQL would look something like at this point (if I have it right):
SELECT Week, Day, Amt, Sum(Amt) Over (Partition By Week, Order By Day) AS Cumul, Spent FROM AllowancesTable
How to get the last column AmtLeft?
Any help would be greatly appreciated...
Thanks
Gordon
Gordon BOCP
Crystalize