MySql sum elements of a column

XCS picture XCS · Jan 3, 2011 · Viewed 108.7k times · Source

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

Answer

nos picture nos · Jan 3, 2011
 select sum(A),sum(B),sum(C) from mytable where id in (1,2,3);