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
how show number of employees hired per year last 5 years include average salary employees hired in years.
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
Post a Comment