This question already has an answer here:
这个问题已经有了答案:
- MySql sum elements of a column 3 answers
- 第3列的MySql和元素
I have a sql table with a user_id
and an integer
我有一个带有user_id和整数的sql表
Is it possible to select integer
from table where user_id
= ? then add all integer results together and return just the one integer result?
是否可以从user_id =的表中选择integer ?然后将所有的整数结果相加,只返回一个整数结果?
2 个解决方案
#1
2
You could do something like
你可以这样做
SELECT sum(integer) As ReturnValue
FROM table
WHERE user_id = [value]
#2
2
yes - try something along of the lines of:
可以——试试下面的方法:
SELECT SUM(integer) FROM tbl WHERE user_id = 'xxx'
#1
2
You could do something like
你可以这样做
SELECT sum(integer) As ReturnValue
FROM table
WHERE user_id = [value]
#2
2
yes - try something along of the lines of:
可以——试试下面的方法:
SELECT SUM(integer) FROM tbl WHERE user_id = 'xxx'