开发者

get the SUM of each Person by the PersonID

I have the following co开发者_Python百科lumns in a table:

SCORE_ID 
SCORE_PERSON_ID 
SCORE_VOTE

The SCORE_PERSON_ID is a variable. I need to sum the SCORE_VOTE per SCORE_PERSON_ID.

Can you suggest of a good way to do that?


You need a GROUP BY and an aggregate function like count or sum

SELECT SCORE_PERSON_ID, sum(SCORE_VOTE) as score
FROM table 
GROUP BY `SCORE_PERSON_ID`


SELECT SUM(SCORE_VOTE)
FROM SCORES
GROUP BY SCORE_PERSON_ID


how about

select sum(SCORE_VOTE) as score  from TABLE group by SCORE_PERSON_ID 

this is sum them up for each person

select sum(SCORE_VOTE)  as score  from TABLE where SCORE_PERSON_ID = 1


I think either this is what you're asking for:

SELECT SUM(SCORE_VOTE)
  FROM <your_table_name>
 WHERE SCORE_PERSON_ID = <some value>

or this:

SELECT SUM(SCORE_VOTE)
  FROM <your_table_name>
 GROUP BY SCORE_PERSON_ID

Hope that helps. Good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜