开发者

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

开发者 https://www.devze.com 2023-04-04 14:42 出处:网络
I have two tables in a mysql database, \"points\" and \"userpoints\". e.g Points: id| pointvalue| message

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

精彩评论

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