我在表格中有以下列:
SCORE_ID
SCORE_PERSON_ID
SCORE_VOTE
SCORE_PERSON_ID是一个变量。我需要根据SCORE_PERSON_ID对SCORE_VOTE求和。
你能建议一个好方法吗?
答案 0 :(得分:4)
您需要GROUP BY
和汇总功能,例如count
或sum
SELECT SCORE_PERSON_ID, sum(SCORE_VOTE) as score
FROM table
GROUP BY `SCORE_PERSON_ID`
答案 1 :(得分:2)
我认为这是你要求的:
SELECT SUM(SCORE_VOTE)
FROM <your_table_name>
WHERE SCORE_PERSON_ID = <some value>
或者这个:
SELECT SUM(SCORE_VOTE)
FROM <your_table_name>
GROUP BY SCORE_PERSON_ID
希望有所帮助。祝你好运。
答案 2 :(得分:2)
SELECT SUM(SCORE_VOTE)
FROM SCORES
GROUP BY SCORE_PERSON_ID
答案 3 :(得分:2)
怎么样
select sum(SCORE_VOTE) as score from TABLE group by SCORE_PERSON_ID
这是为每个人总结的
select sum(SCORE_VOTE) as score from TABLE where SCORE_PERSON_ID = 1