Let’s say I have a table with the following columns:
EmployeeID, PayEntity, HourWorked, Date where PayEntity can be 1:Normal, 2:OverTime, etc How can I get the average of Hours worked for a period of time for example if we do have on my table those data:
1, 1, 40, 7/25/12
1, 2, 5, 7/25/12
2, 1, 30, 7/25/12
The average for this date must be (40+5)+30/2 -- 37.5
Try using a subselect where you find the total hours for each employee per day, and an outer select where you calculate the average per day:
See it working online: sqlfiddle