0
I have the following columns in the table eventos (nome_hosp,cpf_hosp,parametro_evento, data)
.
What I need to do is, where the column value parametro_evento = 1
, perform a line count by separating by CPF, that is, by people.
For example:
- If you have 03 data with CPF(fictional number) equal to 1
It will print me: CPF:1 total: 3
- If you have 03 data with
CPF=1
and 02 data withCPF=2
He’ll print me out: CPF: 1 total:3 CPF: 2 total: 1
Table image
What’s been returning to me:
What I would like to return would be, in place of "Joao" the BPM would be only 1, because according to the database it only has an occurrence with parameter 1 and not 3.
Code:
$result_transacoes = "SELECT * FROM eventos WHERE (timestamp_evento BETWEEN '$de' AND '$ate') GROUP BY cpf_hospede";
$resultado_trasacoes = mysqli_query($conecta, $result_transacoes);
$cont_bpm=0;
while($row_transacoes = mysqli_fetch_assoc($resultado_trasacoes)){
if($row_transacoes['parametro_evento'] == '1') {
$result = mysqli_query($conecta,"SELECT count(*) as total from eventos GROUP BY cpf_hospede");
$data = mysqli_fetch_assoc($result);
$num_bpms= $data['total'];
}
}
I believed that if I made one group by
that would solve my problem, but not.
In your first SELECT you did not inform the aggregation function. In your second SELECT you the aggregation function and the GROUP BY clause but do not list the field by which you are aggregating. That way I have no idea how you unite the information of the two SELECT.
– anonimo
Could you explain better? I did GROUP BY at 1° and 2° select
– João Vitor