47

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
informatik01
  • 16,038
  • 10
  • 74
  • 104
XCS
  • 27,244
  • 26
  • 101
  • 151

3 Answers3

76
 select sum(A),sum(B),sum(C) from mytable where id in (1,2,3);
nos
  • 223,662
  • 58
  • 417
  • 506
13
select
  sum(a) as atotal,
  sum(b) as btotal,
  sum(c) as ctotal
from
  yourtable t
where
  t.id in (1, 2, 3)
GolezTrol
  • 114,394
  • 18
  • 182
  • 210
7

Try this:

select sum(a), sum(b), sum(c)
from your_table
Ike Walker
  • 64,401
  • 14
  • 110
  • 109