Add hours of all employees during the month

Asked

Viewed 53 times

0

I am developing a system in PHP and Mysql where a person does some overtime during the month.

pessoa = id - 5 - int /nome - 15 - varchar /

boletins = id -5 - int / idpessoa - 5 - int / horaextra - time / data - date /

I’d like to generate a report adding up everyone’s overtime all month, but I’m not getting it.

SELECT time_format( SEC_TO_TIME( SUM( TIME_TO_SEC( horaextra ) ) ),'%H:%i:%s') AS horaextra FROM boletins where idpessoa = (numero do id, mas queria listar todos com a hora somada do mes inteiro)
  • Use the GROUP BY idpessoa clause and the SUM aggregation function and the desired month/year condition.

1 answer

0

Try:

SELECT pessoa.nome, TIME_FORMAT(SEC_TO_TIME(SUM(TIME_TO_SEC(boletins.horaextra))), '%H:%i:%s') AS horaextra 
FROM pessoa INNER JOIN boletins ON (pessoa.id = boletins.idpessoa)
WHERE MONTH(boletins.data) = mês_desejado AND YEAR(boletins.data) = ano_desejado
GROUP BY pessoa.nome;

or something similar, according to the DBMS used.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.