I would like to group and list all the rows that have the same value (gruppo_muscolare.nome) and count how many values (esercizio.nome) are related to the same value, but if I use GROUP BY then I only get the single results without the full list.
SELECT
gruppo_muscolare.nome,
esercizio.nome,
COUNT(gruppo_muscolare.nome) AS counter
FROM tabella_allenamento, scheda, esercizio_scheda, esercizio, gruppo_muscolare
WHERE tabella_allenamento.id = 29 AND scheda.id_tabella=tabella_allenamento.id
AND esercizio_scheda.id_scheda=scheda.id AND esercizio.id=esercizio_scheda.id_esercizio
AND gruppo_muscolare.id=esercizio.id_gruppo_muscolare
GROUP BY gruppo_muscolare.nome, esercizio.nome,
gruppo_muscolare.id
ORDER BY counter DESC
I get:
nome nome counter
pettorali Chest Press 1
pettorali incline press hammer 1
quadricipiti Leg Curl 1
while I would like to get:
nome nome counter
pettorali Chest Press 2
pettorali incline press hammer 2
quadricipiti Leg Curl 1
If I use the GROUP BY statement with only a value:
SELECT gruppo_muscolare.nome,
esercizio.nome,
COUNT(gruppo_muscolare.nome) AS counter
FROM tabella_allenamento, scheda, esercizio_scheda, esercizio, gruppo_muscolare
WHERE tabella_allenamento.id = 29 AND scheda.id_tabella=tabella_allenamento.id
AND esercizio_scheda.id_scheda=scheda.id AND esercizio.id=esercizio_scheda.id_esercizio
AND gruppo_muscolare.id=esercizio.id_gruppo_muscolare
GROUP BY gruppo_muscolare.nome
ORDER BY counter DESC
then I get:
nome nome counter
pettorali Chest Press 2
quadricipiti Leg Curl 1
that it’s what I want but a result is missing.
How can I list ALL the results and at the same time also get the correct counter that counts how many esercizio.nome
there are for each gruppo_muscolare.nome
?
Thank you!