1
Good afternoon, I am making a select where I have to show the amounts of services and name of the grouped clients, only that the different dates have to create the line with grouped services and show the different date on each line. How is my code:
select mensalidade_cliente.id_cliente,mensalidade_cliente.dt_mensal,mensalidade_cliente.status,
clientes.nome,
COUNT(pedidos.id) AS QuantidadeServicos
from mensalidade_cliente
INNER JOIN clientes ON clientes.id = mensalidade_cliente.id_cliente
LEFT JOIN pedidos ON pedidos.id_cliente = clientes.id group by pedidos.id_cliente;
As I have to show:
id_cliente | dt_mensal | status| QuantidadeServicos
1 | 2020-05-01 | 1 | 2
1 | 2020-06-01 | 2 | 2
If I take the group by it shows a single line with all the services of all customers. I need help who knows how to answer me thank.
Have you tried putting the
mensalidade_cliente.dt_mensal
in thegroup by
?– Daniel Mendes
@Danielmendes already yes, but then he shows the same client on different dates, but the services remain grouped in different ways.
– Joana
This output you have shown does not match the query shown, but considering that you use LEFT OUTER JOIN maybe your GROUP BY should be per monthly charge_client.id_client since orders.id_client may be NULL.
– anonimo
@anonimo tried too, did not work :(
– Joana