Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want write a query for displaying how many employees are joined in the particular year

Like    1998-6
        2000-8
        2012-10 

Iam writing query it displays result like
1987-09-17 00:00:00.000 1
1989-09-21 00:00:00.000 1
1990-01-03 00:00:00.000 1
1991-05-21 00:00:00.000 1
1993-01-13 00:00:00.000 1
1994-06-07 00:00:00.000 4
1994-08-16 00:00:00.000 1
1994-08-17 00:00:00.000 1
1994-12-07 00:00:00.000 1


But i want to display in 1994-12-07 - 7 like this..

SQL
select  hire_date, count(Employee_Id)
  from  empp
group by hire_date


[edit]SHOUTING removed, Code block added - OriginalGriff[/edit]
Posted
Updated 26-Jul-14 0:57am
v2
Comments
OriginalGriff 26-Jul-14 6:57am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalization if you want to be taken seriously.
Manoj Kumar Choubey 26-Jul-14 8:09am    
select year( hire_date), count(Employee_Id)
from empp
group by year( hire_date)
CHill60 26-Jul-14 9:10am    
Yes. Post as solution!

C#
select year( hire_date), count(Employee_Id)
from empp
group by year( hire_date)
 
Share this answer
 
Hi Chandugg,

Please try following solution. In this solution I create a full example but you can see only final query.

SQL
--Create a Table for employee

Create Table empp
(Id int identity(1,1) primary key,
Employee_Id int,
hire_date datetime
)

---Insert data in table

insert into empp(Employee_Id,hire_date)
values (1,'1987-09-17 00:00:00.000'),
(1,'1989-09-21 00:00:00.000'),
(1, '1990-01-03 00:00:00.000'),
(1,'1991-05-21 00:00:00.000'),
(1,'1993-01-13 00:00:00.000'),
(4,'1994-06-07 00:00:00.000'),
(1, '1994-08-16 00:00:00.000'),
(1,'1994-08-17 00:00:00.000'),
(1,'1994-12-07 00:00:00.000')

--final query for expected result
Select DATEPART(yyyy,hire_Date), count(Employee_Id) from empp
Group by (DATEPART(yyyy,hire_Date))
 
Share this answer
 
Comments
nrdhakshinar 17-Nov-14 5:31am    
thanks
Sandeep Singh Shekhawat 17-Nov-14 6:31am    
Welcome Dear !!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900