I have an example problem about bank transactions. My table contains a lot of data such as Cash, Office, Name, Last Name, Date, ID, Amount, Type ...
Each box (there are several) has several offices, and these in turn have many customers. After a few previous consultations I have reached the next, so I have to leave yes or yes of it:
SELECT Caja, Oficina, MIN(NombreCompleto) AS Persona
FROM (
SELECT Caja, Oficina, DNI, MIN(Nombre+Apellidos) AS NombreCompleto, Importe
FROM miTabla
WHERE Importe > 50
GROUP BY Caja, Oficina, DNI, Importe) as tabla1
GROUP BY Caja, Oficina
ORDER BY Caja, Oficina, Nombre
This shows me the first person in alphabetical order (eg Alberto Álvarez) inside all the offices, inside each box. That is, one person per office.
So now what I need is for a 4th field to appear (apart from cash, office, person, which already shows me the previous query) that is the sum of all the amounts associated with those people that already appear to me.
That is to say, if 5 people appear to me, I want to add the amount that each of them has and that the result appears and repeats itself throughout the entire output.
I am trying to put the SUM (Amount) in several places but it does not work out. I hope you understand me.
Thank you.