Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to write a query to select the year in which most of the employees were hired, that year and the number of employees. How do i do this?
Posted
Comments
JF2015 4-Oct-12 8:43am    
Most means >50%, so just query for that...

1 solution

With aboslutely no idea what your database structure looks like, I'll have to guess....but a GROUP and COUNT will work.

SQL
SELECT
     Year(EmployeeStartDate) AS YearHired, COUNT(EmployeeId) AS EmployeeHiredCount
FROM
    EmployeeDetails
GROUP BY
    Year(EmployeeStartDate)
ORDER BY 
    Count(EmployeeID) DESC



Assuming you've got a table with Employee details and always record their start date, you can use the YEAR function to group and count by that field. See if you can figure out how to select the record you're interested in.
 
Share this answer
 
Comments
ridoy 4-Oct-12 9:01am    
right..+5
bolshie6 4-Oct-12 9:37am    
Thank u :) Works :)
Maciej Los 4-Oct-12 15:35pm    
'Most' = the count of employees hired in a year ;)
+5!

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