Help please SQL... Adding a column of total accumulated in a table
Tonight... I have the task of adding a column of total cumulative to a table that contains a list of transactions. The table contains entries for several accounts.for example
create the table adam_test1
(
account char (4),
date of entry_date,
amount number 4,
Balance number 4
);
insert into adam_test1 values ('1000', January 1, 2000 ", 50", null);
insert into adam_test1 values ('1000', January 2, 2000 ', 40', null);
insert into adam_test1 values ('1000', 3 January 2000', '-50', null ");
insert into adam_test1 values ('1000', January 4, 2000 ', 10', null);
insert into adam_test1 values ('1000', 5 January 2000', '-250', null ");
insert into adam_test1 values ('1000', January 6, 2000', '100', null);
insert into adam_test1 values ('1000', January 7, 2000 ", 50", null);
insert into adam_test1 values ('2000,' 1 January 2000 ', 30', null);
insert into adam_test1 values ('2000', January 2, 2000 ', 10', null);
insert into adam_test1 values ('2000', 3 January 2000', '-520', null ");
insert into adam_test1 values ('2000', January 4, 2000', '140', null);
insert into adam_test1 values ('2000', 5 January 2000', '-4', null ");
insert into adam_test1 values ('2000', January 6, 2000 "," 120", null);
insert into adam_test1 values ('2000', January 7, 2000 ', 57', null);
SQL > select * from adam_test1;
ACCO ENTRY_DAT BALANCE AMOUNT
---- --------- ---------- ----------
1000 1 JANUARY 00 50
1000 2 JANUARY 00 40
1000 3 JANUARY 00-50
1000 4 JANUARY 00 10
1000 5 JANUARY 00-250
1000 6 JANUARY 00 100
1000 7 JANUARY 00 50
2000 1 JANUARY 00 30
2000 2 JANUARY 00 10
2000 3 JANUARY 00-520
2000 4 JANUARY 00 140
2000 JANUARY 5, 00-4
2000-6 JANUARY 00 120
2000-7 JANUARY 00 57
.. I tried a few things to fill the values using rowid, but I was not able to get anything to work - ideas?
Thank you!
Adam
Use MERGE:
merge
into adam_test1 t1
using (
select rowid,
sum(amount) over(partition by account order by entry_date) balance
from adam_test1
) t2
on (t1.rowid = t2.rowid)
when matched
then
update set t1.balance = t2.balance
/
ACCO ENTRY_DAT AMOUNT BALANCE
---- --------- ---------- ----------
1000 01-JAN-00 50 50
1000 02-JAN-00 40 90
1000 03-JAN-00 -50 40
1000 04-JAN-00 10 50
1000 05-JAN-00 -250 -200
1000 06-JAN-00 100 -100
1000 07-JAN-00 50 -50
2000 01-JAN-00 30 30
2000 02-JAN-00 10 40
2000 03-JAN-00 -520 -480
2000 04-JAN-00 140 -340
ACCO ENTRY_DAT AMOUNT BALANCE
---- --------- ---------- ----------
2000 05-JAN-00 -4 -344
2000 06-JAN-00 120 -224
2000 07-JAN-00 57 -167
14 rows selected.
SQL>
SY.
Tags: Database
Similar Questions
-
Hi all
Please help me with this query:
I have data from a table like:
ID | emp_id | salary
1. 100. 200
2. 200 | 400
3. 300. 450
and I need to write a Sql to get the following result:
ID | emp_id | salary | C_Salary
1. 100. 200 | 200
2. 200 | 400. 600
3. 300. 450. 1050
Examples of data include:
with t as
(select 1 i_d, empi_d 100, 200 double sal)
UNION ALL
Select i_d 2, empi_d 200, 400 sal double
UNION ALL
Select 3 i_d, empi_d 300, 450 double sal)
Select * from t
Concerning
RahulHello
Try like this
with t as
(select 1 i_d, empi_d 100, 200 double sal)
UNION ALL
Select i_d 2, empi_d 200, 400 sal double
UNION ALL
Select 3 i_d, empi_d 300, 450 double sal)
Select t.*, sum (sal) over (order by I_D) t C_SalThank you & best regards
Srikkanth.M -
[SOLVED] Help, please! Name of column MySQL to FLEX
Hello!
I want the name of a column in a MySQL database table for my Flex output application. I searched and found the mysql_field_name PHP function.
The NAME of the TABLE is
-stations
The FIELDS in table 'stations' are:
-station_id
-staiton_name
When I run the application now, I get nothing! Try it yourself!
Please, I beg you! Help! I am a beginner Flex/PHP, so if you have any ideas for a solution or a different approach to the resolution of this feature, Post it!
Kind regards
Kenwio
FLEX and PHP code:
OK, this one is solved.
Instead of using the code above, I now use the code below. Works like a charm
Hope this helps someone in the future...
KenwioHERE IS THE FLEX AND PHP CODE:
-
I have a table of the adf, I added a column that contains a button that I created, when I click it must remove this row in the table, but it is not, please help
I don't understand. You use vo and eo for you to use business components.
Again, this kind of code call in trouble.
You must post the changes to make them visible to the eo find vo. You must then run the query for the changes in the business layer strips then you must update the iterator he table is based on.
In your code I see that happen, hooch maybe because it is more often than not formatted and undocumented.
My advice is to do a small test case that you can manage with easy sql. Once you get it to run transfer you the results to the actual application.
Timo
-
I have the table of 3 columns A, B, C. I want to store the sum of columns A B in the C column without using the DML statements. Can anyone help please how to do. ?
11.1 and especially you have virtual column
SQL> create table t 2 ( 3 a number 4 , b number 5 , c generated always as (a+b) virtual 6 ); Table created. SQL> insert into t (a, b) values (1, 2); 1 row created. SQL> select * from t; A B C ---------- ---------- ---------- 1 2 3
Before that, a front insert - trigger
SQL> create table t 2 ( 3 a number 4 , b number 5 , c number 6 ); Table created. SQL> create or replace trigger t_default before insert on t for each row 2 begin 3 :new.c := :new.a+:new.b; 4 end; 5 / Trigger created. SQL> insert into t (a, b) values (1, 2); 1 row created. SQL> select * from t; A B C ---------- ---------- ---------- 1 2 3
-
Hello
I have an emp_job_det with a, b, c columns table. Note that this TABLE ALREADY has DATA OF THESE COLUMNS
IAM now add a new column "D" with forced not null
Fistly I alter the table by adding the single column "D", if I do, the entire column would be created with alll of nulls for the column DEFAULT D
ALTER table emp_job_det Add number D; -do note not null CONSTRAINT is not added
Second... If I try to add the constraint not null, get an eoor as already conatained null values...
(GOLD)
In other words, if I put the query
ALTER table emp_job_det Add number D NOT NULL; -THROWS ERROR AS TABLE ALREADY CONTAINS DATA
So my question is how how can I add a new column with a constraint not null, table already has the data, without falling off the table
Please help me on this issue...
Add the column without constraint, then fill the column. Once all the rows in the table are given in the new column, and then add the constraint not null.
-
Hello thank you for taking the time to everyone reading this,
I have 1 Table with 3 columns
Column 1 - quantity
Column 2 - unit cost
Column 3 - Total amount
I have the user to enter the quantity and unit cost
is it possible to create a mutiplyes function both on a SQL report, which shows me a result.
I tried to use the report attributes > column attributes TOTAL_AMOUNT
HTML expression: #R_QUANTITY # * #UNIT_COST # (Am I close?)
is there another way to gift of this?
Thanks in advance.
Jo3yIf you talk about a report, then I suppose that the user has already entered data in a form and it has been saved in the database.
In this case, it would be easier to do this in the SQL statement that retrieves data
SELECT QUANTITY, UNIT_COST, QUANTITY * UNIT_COST AS TOTAL_AMT FROM TABLE_A
The HTML EXPRESSION is not able to do any arithmetic it is purely a HTML string with a variable capacity of substitution.
Hope that helps,
-Doug-
http://sumnertech.com/
-
using windows 7. used to get information (artist, album, genre, tracks) of music automatically added when Ripper music CDs, but do not get more information? Any help please
Hi George Corbett.
· Did you the latest changes on the computer?
I suggest that you run the windows media player troubleshooting tool and check if it helps.
http://Windows.Microsoft.com/en-us/Windows7/open-the-Windows-Media-Player-settings-Troubleshooter
-
I have NEED of HELP PLEASE I am trying to copy a CD but get an error in the column State of Rip. Has not changed any option, as I just ripped a CD yesterday. HELP PLEASE!
Hello
1. What is the exact error message?
2. is the issue specific to this particular CD/DVD?
3 did you changes to the computer, before the show?
Method 1:
Run the Windows Media Player settings troubleshooter.
Open the troubleshooting Windows Media Player settings Troubleshooter
Method 2:
Change the settings for the extraction of music and the audit.
-
Hello
I'm following link below to show/hide my columns dynamically. See "formatting of column.
http://docs.Oracle.com/CD/E12844_01/doc/BIP.1013/e12187.PDF
According to the doc element can be made in private/public.
<items type="PUBLIC"> <item> <name>Plasma TV</name> <quantity>10</quantity> <price>4000</price> </item> <item>
And even can be used to hide the column with the help of State
<?if@column:/items/@type="PUBLIC"?>
MY QUESTION IS HOW TO DO THIS IN MY XML BELOW?
Here's the part of my XML code that I use in the definition of the data to RTF.
<group name="GH3" source="QH3"> <element name="COLUMN_HEAD3" value="COLUMN_NAME" /> </group> <group name="GH4" source="QH4"> <element name="COLUMN_HEAD4" value="COLUMN_NAME" /> </group>
I'm out like that.
<LIST_GH3> <GH3> <COLUMN_HEAD3>REBILL_TO_OTHER_BUSINESS_UNIT</COLUMN_HEAD3> </GH3> </LIST_GH3> <LIST_GH4> <GH4> <COLUMN_HEAD4>XYZ</COLUMN_HEAD4> </GH4> </LIST_GH4>
In order to use the logic according to the oracle document I want output like this.
<LIST_GH3 type="PUBLIC"> <GH3> <COLUMN_HEAD3>REBILL_TO_OTHER_BUSINESS_UNIT</COLUMN_HEAD3> </GH3> </LIST_GH3> <LIST_GH4 type="PRIVATE"> <GH4> <COLUMN_HEAD4>BLANK</COLUMN_HEAD4> </GH4> </LIST_GH4>
Should what changes I make in my XML to get the result of the execution as above? Help, please. Where should I make changes in the XML above? Name of the Group? Name of the element?
I intend to use it under condition in RTF model to hide the column, but do not know how to set the column as PRIVATE/PUBLIC type in the XML output that is used to populate the data in the RTF while running.
<?if@column:/BTSPIEXP/LIST_GH3/@type=”PUBLIC”?>COLUMN_HEAD3<?end if?>
Kind regards
Patricia K.
Hello
Problem has been resolved. I used the value of the item to determine whether to show it.
Kind regards
Patricia K.
-
Hello
I have spent some time on it and could really use some help please. I have looked at the plot in real time in the help, searched the forum, but the examples isn't enough similarity for me change.
The attached vi is a graph of the waveform (with bars) which I use to show a single value read from a text file. The value in the text file will update once every half hour (from a data logger), for a total of 10 hours (20 values)
I would like to see each point on the graph from left to right with a spacing between the two. The value in the text file will pass (never down) so the plot resulting bars resemble a staircase (but with heights different step). The process will continue with a small break between two periods of update files and previous data points (bars) must therefore be kept (and available by zip, so I can code pretty easily).
Could someone show me how this could be achieved?
Thank you in anticipation
Ray
Hi Ray,
Here are a few examples.
The first - mod bar graph - uses a node back feeding to see if an item has been added to the data file.
You can consider using a graphic as in the second example - graphic bar. With a graphic, you can change the number of data points to resize the waveform table. In this example, a shift register is used to allow only insert new values into the table.
Steve
-
Hello
SQL query to find the total number of source based nonsource passangersbetween source and destination station and passenger station on the same chekindate.
Please help on this script and let me know if you need more details.
---
You use a SELECT statement. Let me know if you need more details.
-
Under Update taking 2 h complete 3000 sets.
UPDATE ARR_TRANSACTIONS ARR
SET = NUMBER99
(SELECT ARR_1.NUMBER99
OF ARR_TRANSACTIONS ARR_1, ARR_HEADER BH
WHERE ARR_1.ARR_ID = BH. ARR_ID
AND BH. FLAG = "Y".
AND ARR_1.LINE_ID = ARR. ORIG_INV_LINE_ID
AND ARR_1.NUMBER9 IS NOT NULL
AND ROWNUM = 1)
WHERE ARR BATCH_ID = 26219
AND ARR. NUMBER99 IS NULL
I added more some condition where to reduce cost and its working fine. But I need to rise more than performance on SQL.
Please help with SQL.
I do not see the number of 3000 lines in the plan - so I guess that the optimizer does not compute with the correct numbers. Could generate the plan with dbms_xplan.display_cursor? This could tell us something about filter predicates and access.
In the given situation, I would check:
- is the access to the index in step 1 (filtered by the relevant conditions: this could be BATCH_ID = 26219) return actually 248 entries (or something similar)?
- Access table in step 2 returning 204 lines (or something similar) after applying the filters given? If the number of lines is much bigger then a Nested Loops is perhaps not a good idea.
To make this much simpler check, you could create a plan with statistics of content (RowSource) given that the plan containing the real and the number of estimated rows.
If the estimated cardinalities are not plausible the next question would be if the statistics are strong and up to date.
-
Help please - issue of calculation of execution time
Hello
Version of DB: database Oracle 11 g Enterprise Edition Release 11.2.0.3.0
Previous thread (RE: help please - issue of calculation of execution time) mode lock, therefore open new thread.
Karthick_Arp thanks for your great help with the merge code.
I modified my code with Merge statement instead of loops and internal loops.
PFB code and output. But still I am negitive values over time of execution because end_time < start_time is coming. Please suggest me how to solve this problem.
1 CREATE OR REPLACE PROCEDURE my_proc
2 EAST
3 sql_string VARCHAR2 (4000);
4 v_start_time TIMESTAMP;
5 v_end_time TIMESTAMP;
6 v_rowcnt NUMBER;
7. START
8 FOR c1 IN (SELECT ROWNUM tab_no, tablename, TYPE
9 FROM stored_ddl_policies by tablename) / * mourning tablename order * /.
10 LOOP
11 sql_string: = q']
12 merge into #tablename # b
13 using (select empkey, id, dt
14de emp_base) on (a.empkey = b.empkey)
15when matched then update set b.id = a.id, b.dt = a.dt] ";
16 sql_string: = REPLACE (sql_string, "#tablename #", c1.tablename);
17 v_start_time: = SYSTIMESTAMP;
18
19 sql_string EXECUTE IMMEDIATE.
20
21 v_end_time: = SYSTIMESTAMP;
22 v_rowcnt: = SQL % ROWCOUNT;
23 DBMS_OUTPUT.put_line (c1.tablename); / * added for display * /.
24 DBMS_OUTPUT.put_line (v_start_time);
25 DBMS_OUTPUT.put_line (v_end_time);
26 INSERT INTO exec_time (TABLE_NAME, START_TIME, END_TIME, EXCUTION_TIME, NO_OF_RECORDS_PROCESSED)
27 VALUES (c1.tab_no |) ' ' || C1. TableName, v_start_time, v_end_time, v_end_time - v_start_time, v_rowcnt);
28 END LOOP;
29
30 COMMIT;
31EXCEPTION
32 THEN THAN OTHERS
33 THEN
34 DBMS_OUTPUT.put_line (SQLERRM);
35END;
16 m
OUTPUT:
select * from exec_time by start_time desc
TABLE_NAME START_TIME, END_TIME EXCUTION_TIME NO_OF_RECORDS_PROCESSED
6 TAB6 31/05/2013 3:07:00.282065 AM 31/05/2013 3:06:47.103731 AM - 00 33 00:00:13.178334
23 TAB23 31/05/2013 3:06:56.159271 AM 31/05/2013 3:06:56.342313 AM + 00 00:00:00.183042 1013
20 TAB20 31/05/2013 3:06:47.104115 AM 31/05/2013 AM + 00 00:00:09.054770 158169 3:06:56.158885
13 TAB13 31/05/2013 3:06:41.668578 AM 31/05/2013 3:06:31.690199 AM - 00 28 00:00:09.978379
7 TAB7 31/05/2013 3:06:41.624134 AM 31/05/2013 3:06:41.668468 AM + 00 00:00:00.044334 0
12 TAB12 31/05/2013 3:06:31.690582 AM 31/05/2013 3:07:00.281522 AM + 00 00:00:28.590940 240715
3 TAB 3 31/05/2013 3:06:24.669461 AM 31/05/2013 3:06:41.623421 AM + 00 00:00:16.953960 47426
2 TAB2 31/05/2013 3:06:24.182326 AM 31/05/2013 AM + 00 00:00:00.486723 5242 3:06:24.669049
8 RAB8 31/05/2013 3:06:21.416823 AM 31/05/2013 3:06:24.181956 AM + 00 00:00:02.765133 28636
1 TAB1 31/05/2013 3:06:16.320679 AM 31/05/2013 AM + 00 00:00:05.095731 132633 3:06:21.416410
16 TAB16 31/05/2013 3:06:07.446056 AM 31/05/2013 AM + 00 00:00:08.874227 421215 3:06:16.320283
11 TAB11 31/05/2013 3:06:07.442987 AM 31/05/2013 3:05:55.361263 AM - 00:00:12.081724-00 60273
19 TAB19 31/05/2013 3:06:03.683463 AM 31/05/2013 3:06:07.445630 AM + 00 00:00:03.762167 77549
15 TAB15 31/05/2013 3:06:00.291696 AM 31/05/2013 3:06:03.683017 AM + 00 00:00:03.391321 77117
10 TAB10 31/05/2013 3:05:57.787733 AM 31/05/2013 AM + 00 00:00:09.654601 517960 3:06:07.442334
18 TAB18 31/05/2013 3:05:56.742873 AM 31/05/2013 3:06:00.291274 AM + 00 00:00:03.548401 105630
24 TAB24 31/05/2013 3:05:55.361707 AM 31/05/2013 3:05:56.742506 AM + 00 00:00:01.380799 15115
4 TAB4 31/05/2013 3:05:18.873303 AM 31/05/2013 3:05:06.966972 AM - 00:00:11.906331-00 49078
21 TAB21 31/05/2013 3:05:13.609759 AM 31/05/2013 3:05:18.872878 AM + 00 00:00:05.263119 56525
22 TAB22 31/05/2013 3:05:09.070048 AM 31/05/2013 AM + 00 00:00:48.717139 451439 3:05:57.787187
5 TAB5 31/05/2013 3:05:06.967411 AM 31/05/2013 3:05:09.069642 AM + 00 00:00:02.102231 773
25 TAB25 31/05/2013 3:05:05.198282 AM 31/05/2013 AM + 00 00:00:08.410911 308670 3:05:13.609193
14 TAB14 31/05/2013 3:04:59.575951 AM 31/05/2013 3:05:05.197701 AM + 00 00:00:05.621750 12118
17 TAB17 31/05/2013 3:04:43.740910 AM 31/05/2013 3:04:59.575503 AM + 00 00:00:15.834593 529
9 TAB9 31/05/2013 3:04:38.286041 AM 31/05/2013 3:04:59.011404 AM + 00 00:00:20.725363 65921
Thanks in advance.
Published by: 1008545 on May 31, 2013 01:40
-
The creation of sequence error. Help, please
I use following script to create the sequence but in error
Error report:
SQL error: ORA-01722: invalid number
01722 00000 - "invalid number."
CREATE SEQUENCES BL_BTN_MASTER_SEQ
MINVALUE 1
MAXVALUE 999999999999999999
INCREMENT BY 1
START WITH (SELECT MAX (BULLETIN_MASTER_ID) + 1
OF BL_BTN_MASTER)
NOCACHE;
FYI... The bulletin_master_id column data type is NUMBER (22.0)
Help, please.
Published by: user11228834 on May 29, 2013 10:22
Published by: user11228834 on May 29, 2013 10:23
Published by: user11228834 on May 29, 2013 10:25Oracle doesn't like the ' (select max (bulletin_master_id) + 1 bl_btn_master)' statement incorporated in the CREATE SEQUENCE statement because if you look at the syntax it expects an acual number.» You can use run immediately to create the sequence in this way:
{code}
declare
number of v_seq;
v_statement varchar2 (200);
Start
SELECT max (bulletin_master_id) + 1
in v_seq
of bl_btn_master;v_statement: = 'CREATE the SEQUENCE BL_BTN_MASTER_SEQ |
"MINVALUE 1' |
"MAXVALUE 999999999999999999' |
' INCREMENT OF 1' |
'START WITH ' | v_seq |
"NOCACHE";execute immediate (v_statement);
end;
{code}
Maybe you are looking for
-
I want to reset to remove Mysearchdial. I can help but then my version of Firefox (I think) opens a tab of choice and none include troubleshooting or reset as indicated on the screenshots.
-
ЗДРАВСТВУЙТЕ! У меня такая проблема: при включении wi - fi bluetooth (f12), отключается звук или. Как только wi - fi bluetooth, музыка снова играет или выключаю. ЧТО ДЕЛАТЬ? ПОМОГИТЕ, ПОЖАЛУЙСТА
-
HP envy 15 laptop: horizontal line on my screen
When I turned on my laptop, I saw a horizontal line on my screen. Most of the time, it's pink and when there is a white or black background, it disappears. Can someone help me with this problem? Thank you
-
Small issue related to Pocket projectors
I bought a Pocket projector a while for personal meetings, I had to do. I use it once in a while, but I want to get more mileage out of it. I want to buy a rocket (not really a fan of apple products) and I found a great deal on one locally. My questi
-
Recently, I replaced my hard drive of my laptop HP Presario DV 9718 with Windows Vista. It is a 4 year old laptop, but it's always a good computer. I finished all downloads for updating Windows (some 200 + GB) as well as 2 Pac Serv and IE 9. I lost m