开发者

How to look up the information using another table as a reference

I have two tables in a mysql database, "points" and "userpoints". e.g

Points:

id  | pointvalue  | message
----------------------------
1   | 5           | comment

Userpoints:

id | uid |pid | timestamp
-------------------------
89 | 5   | 1  | timestamp

How will I get the sum of the points in the userpoints table when it is being linked by the pid in 开发者_如何学Pythonuserpoints?

Using a mysql query?


   SELECT up.uid, SUM(p.pointvalue) total_points
     FROM Userpoints up
LEFT JOIN Points p
       ON up.pid = p.id
    WHERE up.uid = 5;


select sum(p.pointvalue) from userpoints up left join points p on up.pid = p.id group by up.uid

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜