To Group By Hire Date in SQL Server? -


assume following table

employee

employeeid           int firstname            varchar(50) lastname             varchar(50) supervisoremployeeid int salary               money hiredate             datetime 
  1. how show number of employees hired per year last 5 years include average salary employees hired in years.

  2. how show number of employees hired per year last 5 years include average salary employees hired in years.

checkout datepart function in sql. break , group dates based on interval supplied (ie. day, month, year, etc.)

sample:

select     datepart(year,hiredate)     ,count(emplid)     ,avg(salary) employee datediff(year, hiredate, getdate) <= 4 group datepart(year,hiredate)  order datepart(year,hiredate) asc 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -