我有一个包含3列(A,B,C)的表。我想从表中选择一些行,然后在MySQL中返回一行,每行都添加了值......
A B C
1. 2 2 2
2. 4 4 4
3. 6 6 6
如果我选择所有三行,MySql应该返回:
A B C
1. 12 12 12
答案 0 :(得分:63)
select sum(A),sum(B),sum(C) from mytable where id in (1,2,3);
答案 1 :(得分:12)
select
sum(a) as atotal,
sum(b) as btotal,
sum(c) as ctotal
from
yourtable t
where
t.id in (1, 2, 3)
答案 2 :(得分:6)
试试这个:
select sum(a), sum(b), sum(c)
from your_table