Search code examples
mysqlsum

MySQL sum elements of a column


I have a table with 3 columns (A,B,C). I want to select some rows from the table and then the MySQL to return a single row having the values added on each column.

   A B C
1. 2 2 2
2. 4 4 4
3. 6 7 8

MySQL should return in this case, if I select all the three rows:

   A   B  C
1. 12  13 14

Solution

  •  select sum(A),sum(B),sum(C) from mytable where id in (1,2,3);