Home » SQL & PL/SQL » SQL & PL/SQL » Query
Query [message #190053] Tue, 29 August 2006 02:49 Go to next message
jai_162
Messages: 21
Registered: July 2006
Junior Member
I have table emp with the following fields:

Empid EmpName EmpType sal.

Let say if the data is like this:

1 Jai A 200

2 Ram A 1800

3 Shyam B 4000

4 Bhim C 5000

I need the o/p in this form :

1 Jai A 200 2000(Sum of sal of Type )

Regards
Jai
Re: Query [message #190060 is a reply to message #190053] Tue, 29 August 2006 03:13 Go to previous messageGo to next message
dhananjay
Messages: 635
Registered: March 2002
Location: Mumbai
Senior Member
hi,


 
SELECT T.ID,T.NAME,T.JOB_TYPE,T.SAL,T1.TOT_SAL FROM TEST T,
(SELECT JOB_TYPE,SUM(SAL)TOT_SAL FROM TEST GROUP BY JOB_TYPE)T1
WHERE T1.JOB_TYPE=T.JOB_TYPE
ORDER BY T.ID



regards,
Re: Query [message #190070 is a reply to message #190060] Tue, 29 August 2006 03:50 Go to previous messageGo to next message
jai_162
Messages: 21
Registered: July 2006
Junior Member
Thanks for the reply.The given query works.

Thanks again.

Re: Query [message #190121 is a reply to message #190070] Tue, 29 August 2006 05:40 Go to previous messageGo to next message
ehegagoka
Messages: 493
Registered: July 2005
Senior Member
hi!
you could also try this =)


FRGT_UAT@foscopy:SQL>select eid, ename,etype,
  2         sum(sal) over (partition by etype order by eid) totsal
  3  from test
  4  /

       EID ENAME      ETYPE          TOTSAL
---------- ---------- ---------- ----------
         1 Jai        A                 200
         2 Ram        A                2000
         3 Shyam      B                 400
         4 Bhim       C                 500

FRGT_UAT@foscopy:SQL>

Re: Query [message #190334 is a reply to message #190121] Wed, 30 August 2006 04:38 Go to previous message
jai_162
Messages: 21
Registered: July 2006
Junior Member
Thanks for the reply.The output is really a thinking one.
Previous Topic: Tricky SELECT Statement
Next Topic: Cannot connect SYS thru SQL*PLUS only
Goto Forum:
  


Current Time: Thu Dec 05 16:09:57 CST 2024