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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Employee table - group count on expereince

Author  Topic 

sheriefes
Starting Member

9 Posts

Posted - 2009-07-14 : 03:58:27
I have one table : empId empname joiningDate

JOINING DATE STARTING WITH 1975 ONWARDS

I want get the number of employess
1. with less than one year experinece
2. with experience between 1 and 2 years
3. with experience between 3 and 5 years
4. with experience between 5 and 10 years
5. with experience more than 10 years

How can get this in single query

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-14 : 04:02:32
Is it home work or assignment ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

waterduck
Aged Yak Warrior

982 Posts

Posted - 2009-07-14 : 04:25:16
[code]SELECT COUNT(CASE WHEN DATEDIFF(YEAR, dateandtime, getdate())<=2 and DATEDIFF(YEAR, dateandtime, getdate())>1 then dateandtime END)
FROM TABLE[/code]
tips ^^


Hope can help...but advise to wait pros with confirmation...
Go to Top of Page

saran_d28
Starting Member

36 Posts

Posted - 2009-07-14 : 06:12:31
seelct count(case when experience = 0 then 1) as lessonyear,
count(case when experience between 1 and 2 then 1) as 1to2year,
count(case when experience between 3 and 5 then 1) as 3to5year
from

(
Select datadiff(y,joiningdate,getdate()) as experience from mytable
) as main
Go to Top of Page
   

- Advertisement -