Home » SQL & PL/SQL » SQL & PL/SQL » running total (oracle 10g)
running total [message #430409] Tue, 10 November 2009 05:52 Go to next message
mohan1760
Messages: 59
Registered: June 2008
Member
In below example column 2 and 3 are coming from one table.
i want to implement first column something like shown in below example...same as running total
in column 1 but first record of column 1 should start with 3.
after that 3+8=11,11+1=12...and so on....

3 8 NUMBER
11 1 Alpha9
12 8 Alpha9
20 6 Alpha9
26 8 NUMBER

Thanks in advance..
Re: running total [message #430411 is a reply to message #430409] Tue, 10 November 2009 06:00 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Show us what the data that you want to start with is, and what the data that you want to end up with is.
Re: running total [message #430416 is a reply to message #430411] Tue, 10 November 2009 06:08 Go to previous messageGo to next message
mohan1760
Messages: 59
Registered: June 2008
Member
start with


8 NUMBER
1 Alpha9
8 Alpha9
6 Alpha9
8 NUMBER

end with

3 8 NUMBER
11 1 Alpha9
12 8 Alpha9
20 6 Alpha9
26 8 NUMBER

the thing which creats problem
is that i want to start running total by 3 not by 1...after that it is easy to manipulate...fyi first column is dummy column for calculation.
Re: running total [message #430417 is a reply to message #430409] Tue, 10 November 2009 06:09 Go to previous messageGo to next message
Michel Cadot
Messages: 68733
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version with 4 decimals.

Post a working Test case: create table and insert statements along with the result you want with these data.

Regards
Michel
Re: running total [message #430421 is a reply to message #430417] Tue, 10 November 2009 06:16 Go to previous messageGo to next message
mohan1760
Messages: 59
Registered: June 2008
Member
how to send insert statements?...
Re: running total [message #430425 is a reply to message #430421] Tue, 10 November 2009 06:18 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
Type them out as you would any other part of a post. (although include them in [code][/code] tags
Re: running total [message #430426 is a reply to message #430421] Tue, 10 November 2009 06:25 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Quote:
how to send insert statements?...

That's funny.

create table test_097 (col_1 number, col_2 number, col_3 varchar2(30),ord number);

insert into test_097 values (null,8 ,'NUMBER',1);
insert into test_097 values (null,1	,'Alpha9',2);
insert into test_097 values (null,8	,'Alpha9',3);
insert into test_097 values (null,6	,'Alpha9',4);
insert into test_097 values (null,8	,'NUMBER',5);

commit;

select col_1
      ,col_2
      ,col_3
      , nvl(sum(col_2) over (order by ord rows between unbounded preceding and 1 preceding) ,0) + 3
from   test_097;
Re: running total [message #430427 is a reply to message #430426] Tue, 10 November 2009 06:35 Go to previous messageGo to next message
mohan1760
Messages: 59
Registered: June 2008
Member
i thought there might be some easy way to send insert statement
other than typing..
anyways that solves my problem..thanks JRowbottom
Re: running total [message #430432 is a reply to message #430427] Tue, 10 November 2009 06:58 Go to previous message
mohan1760
Messages: 59
Registered: June 2008
Member
yeah thats funny... Smile
Previous Topic: Group by Hours - Show Missing Hours
Next Topic: Query
Goto Forum:
  


Current Time: Sun Feb 09 07:44:15 CST 2025