我有桌子:
id name amount
--------------------------
1 abc 1
2 abc 2
3 abc -3
4 def 4
我想得到每个名字的总和== abc,我的意思是1 + 2 +( - 3)= 0;
如何在MySql中执行此操作?
答案 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'