Hello, I'm doing the following query
SELECT p.id, c.nome, v.titulo, count(v.titulo)
FROM passageiros AS p
LEFT JOIN clientes AS c ON c.id = p.id_cliente
LEFT JOIN viagens AS v ON v.id = p.id_viagem
GROUP BY v.titulo;
And it is returning the following result:
id| nome | titulo | count(v.titulo) 1 | 'bruno' | 'gramado' | 5 6 | 'alea vang'| 'gramado - mundo magico'| 5 11| 'bruno' | 'beto carrero' | 3 14| 'bruno' | 'caminhos rurais' | 6
But what I would like is for it to return the list of each of the names of each title together with the total count of that title:
id| nome | titulo | count(v.titulo) 1 | 'bruno' | 'gramado' | 5 2 | 'tamires' | 'gramado' | 5 3 | 'christen wiggins' | 'gramado' | 5 4 | 'justine howard' | 'gramado' | 5 5 | 'anika hammond' | 'gramado' | 5 6 | 'alea vang' | 'gramado - mundo magico' | 5 7 | 'fredericka jensen'| 'gramado - mundo magico' | 5 8 | 'alexa duncan' | 'gramado - mundo magico' | 5 9 | 'lynn mclean' | 'gramado - mundo magico' | 5 10| 'allegra cantrell' | 'gramado - mundo magico' | 5 11| 'bruno' | 'beto carrero' | 3 12| 'tamires' | 'beto carrero' | 3 13| 'christen wiggins' | 'beto carrero' | 3 14| 'bruno' | 'caminhos rurais' | 6 15| 'tamires' | 'caminhos rurais' | 6 16| 'christen wiggins' | 'caminhos rurais' | 6 17| 'alexa duncan' | 'caminhos rurais' | 6 18| 'lynn mclean' | 'caminhos rurais' | 6 19| 'allegra cantrell' | 'caminhos rurais' | 6
EDIT:
When doing the query using GROUP BY v.titulo, p.id;
I have the return of the complete list of names, however the count
returns only 1
on all lines.
I tried to create count
inside a subquery, but because it returned several results, the search was not successful.