I've got a database table called "hours" which has the following fields: "employee_id" (INT), "time_on" (DATETIME), and "time_off" (DATETIME)
. I want to see which employee logged the most hours in a month.
I'm thinking I need a Subquery but I'm not very good with MySQL, and I cannot wrap my head around the query I need. I want to select all rows from this month with:
"... MONTH(time_on) = ".$this_month_object->format('m')."... "
Then with those rows, I want to select the "employee_id" field with the highest seconds worked using something like:
SUM(time_to_sec(TIMEDIFF(time_off, time_on)))
The last few hours have proved fruitless and I need some fresh ideas.