I have a system where user logs in and out of the tool several times in the day during their working hours. I need to calculate the amount of time it was logged:
The columns LOGOUT
and LOGIN
are in seconds.
SELECT DATA,USUARIO,SUM(PERIODO_LOGADO) AS TOTAL_LOGADO
FROM (
SELECT DATA,USUARIO,LOGOUT-LOGIN AS PERIODO_LOGADO
FROM HISTORICO_LOGIN
GROUP BY DATA,USUARIO,LOGOUT-LOGIN
) SUB
GROUP BY DATA,USUARIO
This query works, but there is the case of employees who work at dawn, and end up having the time accounted for on separate days.
How to merge the two times or calculate the total hours worked dynamically?