---------------- -------------------- -------------------- -------------------- ---------------- ---------------- ----------------------- ---------------- ----------- ----------------
7505 DOYLE JEAN K 671 7839 4/4/1985 2850
7506 DENNIS LYNN S 671 7839 10/5/1985 2750
7507 BAKER LESLIE D 671 7839 9/6/1985 2200
7499 ALLEN KEVIN J 670 7698 12/4/1984 1600 300 30
7521 WARK CYNTHIA D 670 7698 4/2/1985 1250 500 30
7369 SMITH JOHN Q 667 7902 12/5/1984 800
26.List out the no.of employees for each month and year, in the ascending order based on the year, month.
27.List out the department id having atleast four employees.
28.How many employees in January month.
29.How many employees who are joined in January or September month.
30.How many employees who are joined in 1985.
31.How many employees joined each month in 1985.
32.How many employees who are joined in March 1985.
33.Which is the department id, having greater than or equal to 3 employees joined in April 1985Please send me the query for the above questions. Take Your own time for this.

Jignesh TrivediPosted Jun 7, 2013, 3:58 AM
hi,
Try following Query....
create table #emp
(
employeeId int,
lastName varchar(25),
firstName varchar(25),
middleName varchar(25),
jobId int,
managerId int,
hireDate date ,
salary int,
comm varchar(25),
departmentId int
)
insert into #emp
values(7505,'DOYLE','JEAN','K','671','7839','4/4/1985','2850',NULL,30 ),
(7506,'DENNIS','LYNN','S','671','7839','10/5/1985','2750',NULL,30 ) ,
(7507,'BAKER','LESLIE','D','671','7839','9/6/1985','2200',NULL,40 ),
(7499,'ALLEN','KEVIN','J','670','7698','12/4/1984','1600',300,30 ),
(7521,'WARK','CYNTHIA','D','670','7698','4/2/1985','1250',500,30 ),
(7369,'SMITH','JOHN','Q','667','7902','12/5/1984','800',NULL,20)
select * from #emp
Select a.Month,A.Year,COUNT(1) As NoOfEmp from (
select year(hireDate) as Year,MONTH(hireDate) as Month, employeeId from #emp) A
Group by A.Month,A.Year
Order by A.Year,A.Month
select departmentId from #emp
group by departmentId having COUNT(1) > 3
select COUNT(1) from #emp
group by MONTH(hireDate) having MONTH(hireDate) = 12
select COUNT(1) from #emp
where MONTH(hireDate) in (1,9)
select COUNT(1) from #emp
where year(hireDate) = 1985
Select a.Month,A.Year,COUNT(1) As NoOfEmp from (
select year(hireDate) as Year,MONTH(hireDate) as Month, employeeId from #emp) A
Group by A.Month,A.Year having A.Year = 1985
Order by A.Year,A.Month
select COUNT(1) from #emp
where year(hireDate) = 1985 and MONTH(hireDate)= 3
select departmentId from #emp
where year(hireDate) = 1985 and MONTH(hireDate)= 4
group by departmentId having COUNT(1)>=3
it might help you.
Bineesh ViswanathPosted Jun 11, 2013, 7:59 AM