I have to take out the total amount for each unit that I have in my table, the problem is that a record that supposedly belongs to unit 3 belongs to unit 1, I do not know how to group it so that it is correct, this is my query.
select SUM(TOTAL) as total, SUBSTRING(UNIDAD,1,1) as unidad from estruc_programatica group by unidad;
I can only get it from the third table, which I show in the image but I want the table in the middle, the record that I have to group with unit 1 is 3180, it would be {1100,1200, 3180} unit 1 , {2300} unit 2 and {3900, 3050} unit three. I've been trying to get it out for a while, but I can not.