Home » SQL & PL/SQL » SQL & PL/SQL » SQL QUERY (oracle 11g 32-bit, windows7)
SQL QUERY [message #664797] Fri, 04 August 2017 19:47 Go to next message
shawaj
Messages: 59
Registered: January 2016
Member
Hello everyone, I have the table T3 and i need data in this format.
ENAME	SAL	V_SAL
-----------------------------
A	10	10	
B	20	30	
C	30	60	
D	40	100
Please help me.
Thanks in advance..
CREATE TABLE T3(ENAME VARCHAR2(20),SAL NUMBER);

INSERT INTO  T3 VALUES('A',10);
INSERT INTO  T3 VALUES('B',20);
INSERT INTO  T3 VALUES('C',30);
INSERT INTO  T3 VALUES('D',40);
COMMIT;

Select * from t3;

ENAME                       SAL                                                 
-------------------- ----------                                                 
A                            10                                                 
B                            20                                                 
C                            30                                                 
D                            40  

Re: SQL QUERY [message #664798 is a reply to message #664797] Fri, 04 August 2017 19:59 Go to previous messageGo to next message
BlackSwan
Messages: 25751
Registered: January 2009
Location: SoCal
Senior Member
solution could include LAG

What have you tried so far?
Re: SQL QUERY [message #664799 is a reply to message #664798] Fri, 04 August 2017 21:19 Go to previous messageGo to next message
shawaj
Messages: 59
Registered: January 2016
Member
Thanks for quick reply..
I am using like this
select ename,sal,lag(sal) over(order by ename)+sal V_sal from t3;

ENAME                       SAL     V_SAL
-------------------- ---------- ----------
A                            10
B                            20         30
C                            30         50
D                            40         70
but it is not what is want.
Re: SQL QUERY [message #664800 is a reply to message #664799] Fri, 04 August 2017 23:28 Go to previous messageGo to next message
Michel Cadot
Messages: 65255
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
it is not what is want.
And what explaining what you want with words this will prevent from any false interpretation?

Re: SQL QUERY [message #664807 is a reply to message #664799] Sat, 05 August 2017 07:28 Go to previous messageGo to next message
Solomon Yakobson
Messages: 2687
Registered: January 2010
Location: Connecticut, USA
Senior Member
shawaj wrote on Fri, 04 August 2017 22:19

I am using like this
You need SUM, not LAG:

SQL> select ename,sal,sum(sal) over(order by ename) from t3;

ENAME                       SAL SUM(SAL)OVER(ORDERBYENAME)
-------------------- ---------- --------------------------
A                            10                         10
B                            20                         30
C                            30                         60
D                            40                        100

SQL>

SY.
Re: SQL QUERY [message #664860 is a reply to message #664807] Tue, 08 August 2017 21:28 Go to previous message
shawaj
Messages: 59
Registered: January 2016
Member
Thanks Solomon Yakobson.
Previous Topic: ORA-29279: SMTP permanent error: Unable to relay
Next Topic: extract portion of strings
Goto Forum:
  


Current Time: Sat Dec 16 00:34:20 CST 2017

Total time taken to generate the page: 0.01893 seconds