I'm trying to generate a ranking of faults for HR.
Fault logging is done in a separate table in the Employee registry. I need to bring the list of active employees and the amount of absences he has had in the company, but I want to order from the employee who had more absences for what he had less.
I did the SQL below, but it only brings the employees who have failed:
select rh.NOME_FUNCIONARIO, COUNT(registro_faltas_atraso.CPF) as Total from RH
JOIN registro_faltas_atraso
on registro_faltas_atraso.CPF =rh.cpf
where
rh.TIPO_CONTRATO !='Dispensado'
GROUP BY rh.NOME_FUNCIONARIO
ORDER BY desc total