Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query

Author  Topic 

newuser123
Starting Member

7 Posts

Posted - 2010-06-25 : 05:25:58
I have 2 tables with following data

T1
eid month sal
1 jan 100
1 feb 100
2 jan 200
2 feb 200
3 jan 300
3 feb 300
3 mar 300
1 mar 100
4 jan 400

T2
eid dept
3 ad
2 HR
1 IT
4 IT

I want the dept wise salary.

plz tell me the query how i can ????

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-06-25 : 05:29:06
use INNER JOIN on the 2 table on column eid

and then use sum() on the salary with group by dept


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

newuser123
Starting Member

7 Posts

Posted - 2010-06-25 : 05:42:13
can u plz tell me the query..i am using the same logic but not returning proper data
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-06-25 : 05:47:45
can you post your query ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

newuser123
Starting Member

7 Posts

Posted - 2010-06-25 : 05:50:06
select sum(t1.sal)
from t1 t1 where eid in
(select eid from t2 t2
where t2.eid = t1.eid )

i want dept also
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-06-25 : 05:54:42
quote:
Originally posted by khtan

use INNER JOIN on the 2 table on column eid

and then use sum() on the salary with group by dept


KH
[spoiler]Time is always against us[/spoiler]






select t2.dept, sum(t1.sal)
from t1 inner join t2 on t1.eid = t2.eid
group by t2.dept



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -