0
Hello, the error now is that it is adding the Codsector. The values would be 6 and 3, but is coming 6 and 6. Follow photos and codes.
SELECT *, COUNT(`funcionario`.`funcionario_CodSetor`) AS total
FROM `funcionario`
JOIN `setor` ON `setor`.`CodSetor` = `funcionario`.`funcionario_CodSetor`
JOIN `horario` ON `horario`.`horario_CodSetor` = `funcionario`.`funcionario_CodSetor`
JOIN `cbo` ON `cbo`.`CodCBO` = `funcionario`.`funcionario_CodCBO`
JOIN `familiacbo` ON `familiacbo`.`CodFamilia` = `cbo`.`cbo_CodFamilia`
WHERE `funcionario_CodEmpresa` = '32'
GROUP BY `funcionario`.`funcionario_CodSetor`
Without giving the Join in schedule of the sector becomes normal
Are you grouping by the field you are counting? You are supposed to group by everyone else except for this. Try to change the
COUNT
for this:COUNT(DISTINCT funcionario.funcionario.Cod_Setor)
.– João Martins
Using Distinct returns only the value 1 in the two fields.
– José Luis