The problem is the following: I have a query which takes all the information of a teacher including with his two salaries, which I have to add and show them by calendar, previously in another question they answered that I could make the sum by groups , that is, I use the SUM(tabla1+tabla2)
and I do GROUP
per calendar but the numbers go very high and I do not understand why.
This is the query that correctly throws me the values without grouping them:
SELECT profesores.nombre_profe ,
profesores.apellido_paterno ,
profesores.apellido_materno ,
puestos.puesto1 ,
puestos.puesto2 ,
(sueldos.sueldo1 + sueldos.sueldo2) AS total ,
calendarios.nombre_calendario
FROM sueldos
INNER JOIN profesores ON sueldos.profesores_id = profesores.id
INNER JOIN puestos ON puestos.profesores_id = profesores.id
INNER JOIN calendarios ON sueldos.calendarios_id = calendarios.id
WHERE profesores.id = 378;
In this query I do not use the SUM since it gives very exaggerated numbers and the result of this is:
It shows you the total and the calendars, what I want to do is show them grouped by calendar. That is, add all the totals of that calendar.
This is my query where I group by calendar and it gives me big values:
SELECT profesores.nombre_profe ,
profesores.apellido_paterno ,
profesores.apellido_materno ,
puestos.puesto1 ,
puestos.puesto2 ,
SUM(sueldos.sueldo1 + sueldos.sueldo2) AS total ,
calendarios.nombre_calendario
FROM sueldos
INNER JOIN profesores ON sueldos.profesores_id = profesores.id
INNER JOIN puestos ON puestos.profesores_id = profesores.id
INNER JOIN calendarios ON sueldos.calendarios_id = calendarios.id
WHERE profesores.id = 378
GROUP BY calendarios.nombre_calendario;
There is some way to do it without the results going too high, I really do not know why the results are going so high.