View previous topic :: View next topic
|
Author |
Message |
i_at_forum
New User
Joined: 29 Dec 2005 Posts: 10
|
|
|
|
I have 2 tables, DEPT & EMPLOYEE.
DEPT:
Dept Name
Dept No
Dept Loc
EMPLOYEE:
Employee Name
Employee Address
Salary
Dept No
I need an SQL to display Dept Name, Dept Loc, Dept No along with count of employees in each Dept.
Can anyone provide me with the query. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
Can anyone provide me with the query
|
better than that, we can help you build your own query. what do you have so far? |
|
Back to top |
|
|
Srihari Gonugunta
Active User
Joined: 14 Sep 2007 Posts: 295 Location: Singapore
|
|
|
|
Please try the following query.
Code: |
SELECT A.DEPTNAME,A.DEPTNO,A.DEPTLOC,B.CNT FROM
DEPT A, (SELECT DEPTNO, COUNT(*) as CNT from EMPLOYEE
GROUP BY DEPTNO) AS B
WHERE A.DEPTNO=B.DEPTNO |
|
|
Back to top |
|
|
naveengec
New User
Joined: 24 Mar 2007 Posts: 35 Location: pune
|
|
|
|
Please try it...
select dept_name, dept_loc, dept_No, (select count(B.DEPT_NO) FROM EMPLOYEE B WHERE A.DEPT_NO=B.DEPT_NO) AS COUNT_EMP
FROM DEPT A |
|
Back to top |
|
|
i_at_forum
New User
Joined: 29 Dec 2005 Posts: 10
|
|
|
|
thank you... |
|
Back to top |
|
|
|