0
Hello, I’m doing the following consultation
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 she’s returning me 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 her to return the list of each of the names of each title along with the Count total 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 making 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 every line.
I tried to create the count
within a subquery, but as it returns multiple results, the search was unsuccessful.
I was almost on the right track, in my tests I ended up making a consultation similar to this, but I was making the wrong comparison on
where
, thank you very much.– bruno101
dough, fuck up =]
– rLinhares