Hi, I have the same problem as in this question ( Group query without losing different records ), it's complicated explain it.
When the results of the records are grouped, information is lost, for example I have data in the customer table and in the sales table, I need to know on which date the sale was made to said customer, so if I want to add the sales for each client would be used group by ventas.id_cliente
, but in that grouping the dates are lost because they are for sale, when grouping by ventas.id_venta
then if the dates that I need to know are visualized but what I really need is that when grouping it by ventas.id_cliente
, in term of 30 days if that customer bought something, then in a term of 60 days the sales of that client and in 90 days the sales of that client, grouped by ventas.id_cliente
, I can not determine if there were sales 30 days ago because the sales date of 30 days ago is lost in the grouping by id_cliente
. So the question is, how to avoid losing that data?
PS: Ok, I'll try to explain it better: here I put an image of the tables grouped by id_venta
They are two records because that client has two sales, one sale on each date respectively, the fields shown with 0_30 refer to if that sale is 30 days old, the field 30_60 if the sales have 60 days of antiquity, and so on. But when I group it by clients, the record of the most current date disappears and I need you to tell it so that the result is like this:
This is grouped by client_id
In this case, it is as if it does not take into account the record of the most current date, when grouped by client_id it is lost.