How to add 2 columns per calendar in MySQL

1

I have the following table:

I want to do the sum of sueldo1 and sueldo 2 , use SUM(); but that makes me add the two columns but in all the calendars.

Is there any way to do the sum of both columns but by calendar?

That is, add the 2 columns of the calendar 7 and give me a Total per calendar. And so on for all calendars or is there an alternative to make those sums from PHP and avoid doing so in MySQL ?

    
asked by Eduardo Javier Maldonado 15.05.2017 в 21:32
source

2 answers

2

I think you're looking for something like that

SELECT SUM(SUELDO1 + SUELDO2)
FROM TABLA
GROUP BY CALENDARIOS_ID

Or if you want each column separately it would be

SELECT SUM(SUELDO1),
SUM(SUELDO2)
FROM TABLA
GROUP BY CALENDARIOS_ID

and you could add a clause where if you only want to see those of a particular id

WHERE
CALENDARIOS_ID = 7
    
answered by 15.05.2017 / 21:36
source
0

Sum of columns salary1 and salary2 grouped by calendars_id

select calendarios_id, sum(sueldo1), sum(sueldo2) 
    from tabla 
      group by 1 
      order by 1;
    
answered by 15.05.2017 в 21:41