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
 SQL Commands - Select

Author  Topic 

sureshsmanian
Starting Member

31 Posts

Posted - 2009-10-18 : 02:34:13
Hi
I have two tables.
Employee
(Eno -- PK, Ename, Deptno -- FK refers Dept table, Gender)

Dept
(Deptno -- PK, Deptname, Mgrno)

Question : I need a sql command to display the Deptno, Deptname and number of male employees in each department.

Deptno Deptname MaleCount
------ -------- ---------


---- ------- ------

Thanks in advance

Regards
SSM

fanzhouqi
Starting Member

4 Posts

Posted - 2009-10-18 : 09:41:37
select Deptno
,Deptname
, MaleCount = count(1)
from Dept a
inner join Employee b on a.Deptno = b.Deptno
where b.Gender = 'Male'
group by Deptno ,Deptname
Go to Top of Page

sureshsmanian
Starting Member

31 Posts

Posted - 2009-10-19 : 03:41:45
Thanks a lot. it is working fine.

Regards
SSM
Go to Top of Page

sureshsmanian
Starting Member

31 Posts

Posted - 2009-10-19 : 03:43:31
Thanks a lot. it is working fine.

Regards
SSM
Go to Top of Page
   

- Advertisement -