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.
| Author |
Topic |
|
sheriefes
Starting Member
9 Posts |
Posted - 2009-07-14 : 03:58:27
|
| I have one table : empId empname joiningDateJOINING DATE STARTING WITH 1975 ONWARDSI want get the number of employess1. with less than one year experinece2. with experience between 1 and 2 years3. with experience between 3 and 5 years4. with experience between 5 and 10 years5. with experience more than 10 yearsHow 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] |
 |
|
|
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... |
 |
|
|
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 3to5yearfrom (Select datadiff(y,joiningdate,getdate()) as experience from mytable) as main |
 |
|
|
|
|
|