|
|
| Author |
Message |
murali_andaluri
New User
Joined: 07 May 2005 Posts: 22
|
|
|
|
Hi Friends,
i need SQL query for below reqirement
EMPLOYEE table, with columns EMPID, DEPTID, SALARY.
Write SQL Query to display
a. DEPTID & Number of employees (showing all departments)
b. DEPTID & Number of employees (showing only departments that have > 10 employees)
c. Count of departments that have > 10 employees |
|
| Back to top |
|
 |
References
|
Posted: Thu Oct 04, 2007 3:57 pm Post subject: Re: SQL query to display |
 |
|
|
 |
raviprasath_kp Warnings : 1 Active User
Joined: 20 Feb 2005 Posts: 66 Location: chennai
|
|
|
|
a. DEPTID & Number of employees (showing all departments)
select depid, count(empid) from employeetable;
b. DEPTID & Number of employees (showing only departments that have > 10 employees)
select depid,count(empid) employeetable
where count(empid) < 10
c. Count of departments that have > 10 employees
same vice versa
please correct me if i am wrong |
|
| Back to top |
|
 |
mahi
Active User
Joined: 04 Apr 2006 Posts: 62 Location: Pune
|
|
|
|
| You have to use the group by function to get the number of employyees din a dept... |
|
| Back to top |
|
 |
mahi
Active User
Joined: 04 Apr 2006 Posts: 62 Location: Pune
|
|
| Back to top |
|
 |
nuthan
Active User
Joined: 26 Sep 2005 Posts: 152 Location: Bangalore
|
|
|
|
HI,
TRY THIS
SELECT DEPTID, COUNT(EMPID) FROM EMPLOYEE GROUP BY DEPTID;
SELECT DEPTID, COUNT(EMPID) FROM EMPLOYEE GROUP BY DEPTID HAVING COUNT(EMPID) > 10;
SELECT COUNT(*) FROM EMPLOYEE GROUP BY
DEPTID HAVING COUNT(EMPID) > 10; |
|
| Back to top |
|
 |
murali_andaluri
New User
Joined: 07 May 2005 Posts: 22
|
|
|
|
Hi Nutan,
thank you very much for your quick response. |
|
| Back to top |
|
 |
Moved: Fri Oct 05, 2007 1:42 pm by dick scherrer From DB2 to Interview Questions |
|
|