August 1, 2003 at 4:33 am
Hi Guys,
I have a simple requirement. Can anyone of you guys help me. My requirement is -
1. I have a table with one column
CREATE TABLE table1 (col1 int)
INSERT INTO table1 values (1);
INSERT INTO table1 values (2);
INSERT INTO table1 values (3);
INSERT INTO table1 values (4);
INSERT INTO table1 values (5);
SELECT * FROM table1 = will give all values as
1
2
3
4
5
but I want a SQL to retrive data as
col1 calc_col
---- --------
1 1
2 3
3 6
4 10
5 15
Can any one of you help me... Thanks in Advance
August 1, 2003 at 4:51 am
If col1 is key to table1 and it is in ascending order always then you can use construct similar to following
SELECT a.COL1,(SELECT Sum(b.col1)
FROM table1 b
where b.col1 <= a.col1) Caclc_col
from table1 a
...Sorry for double post 🙂
Edited by - rajeshpatavardhan on 08/01/2003 04:52:14 AM
August 1, 2003 at 4:54 am
quote:
If col1 is key to table1 and it is in ascending order always then you can use construct similar to followingSELECT a.COL1,(SELECT Sum(b.col1)
FROM table1 b
where b.col1 <= a.col1) Caclc_col
from table1 a
...Sorry for double post 🙂
Edited by - rajeshpatavardhan on 08/01/2003 04:52:14 AM
Removed mine as yours is the more correct method, just having a brain @#$% today.
August 1, 2003 at 5:00 am
Thank you very much guys, it works... 🙂
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply