如何在MySql中获取值的总和

时间:2014-10-22 11:41:17

标签: mysql

我有桌子:

id        name      amount
--------------------------
1         abc       1
2         abc       2
3         abc       -3
4         def       4

我想得到每个名字的总和== abc,我的意思是1 + 2 +( - 3)= 0;

如何在MySql中执行此操作?

5 个答案:

答案 0 :(得分:1)

SELECT SUM(amount) FROM table WHERE name = 'abc';

答案 1 :(得分:0)

不确定mySQL,但“标准”SQL将是:

select sum(amount) from yourTableName where name='abc'

答案 2 :(得分:0)

SELECT SUM(amount) AS total FROM table WHERE name = 'abc'

答案 3 :(得分:0)

SELECT name, SUM(amount) from Table GROUP BY name;

答案 4 :(得分:0)

SELECT SUM(amount)
FROM tableName
WHERE name='abc'