0
Good evening, I have to group and count how many employees I have with sex and age group. Follow the html code
<div class="card" style="margin-top: 5%;">
<div class="card-header text-center">
Quantificação de Empregados por faixas etárias
</div>
<table class="table table-striped table-bordered text-center" style="height: 100%; width: 100%;">
<<thead>
<tr>
<th></th>
<th style="text-align: center;">Homens</th>
<th style="text-align: center;">Mulheres</th>
</tr>
</thead>
<tbody>
<tr>
<th style="width: 30%">Maiores de 45 anos</th>
<td>1</td>
<td>1</td>
</tr>
<tr>
<th style="width: 30%">Entre 18 e 45 anos</th>
<td>2</td>
<td>2</td>
</tr>
<tr>
<th style="width: 30%">Menores de 18 anos</th>
<td>2</td>
<td>2</td>
</tr>
</tbody>
</table>
</div>
Example, I have to show :
Masculino Maiores que 45 anos - 2 Masculino Entre 18 e 45 anos - 5 Feminino Maiores que 45 anos - 1 Feminino Entre 18 e 45 anos - 3
Follow the sql code I’m using, but is giving error:
SELECT *, CASE (funcionario.funcionario_Sexo)
WHEN F COUNT(funcionario.funcionario_Sexo) AS sexoF
AND
CASE (funcionario.funcionario_Sexo)
WHEN M COUNT(funcionario.funcionario_Sexo) AS sexoM),
TIMESTAMPDIFF (YEAR, `funcionario`.`funcionario_DataNac`, CURDATE())
AS idade_Funcionario
FROM `funcionario` WHERE `CodEmpresa` = '30'
GROUP BY `funcionario`.`funcionario_Sexo`
I found how to do, but this returning me the equal sum in all.
SELECT funcionario_DataNac, funcionario_Nome, funcionario_Sexo,
COUNT(funcionario_Sexo) AS sexo,
COUNT( CASE WHEN TIMESTAMPDIFF(YEAR, funcionario_DataNac, CURDATE()) > 45 THEN 1 ELSE '' END) AS maiorQue,
COUNT( CASE WHEN TIMESTAMPDIFF(YEAR, funcionario_DataNac, CURDATE()) <= 45 AND TIMESTAMPDIFF(YEAR, funcionario_DataNac, CURDATE()) >= 18 THEN 1 ELSE '' END) AS entre,
COUNT( CASE WHEN TIMESTAMPDIFF(YEAR, funcionario_DataNac, CURDATE()) < 18 THEN 1 ELSE '' END) AS menosQue
FROM `funcionario`
WHERE codEmpresa = 30
GROUP BY funcionario_Sexo
What mistake?.....
– Sam
Do you have anything developed in
PHP
or the doubt is only ofsql
?– Thiago Drulla
I have to generate the report in php via codeigniter, I already have the structure, but I need to know the same sql. or if possible even via php.
– José Luis