嘿,大家好,我有一个查询,它工作正常,但我想添加另一个表。我想要添加的邀请表有两个字段:用户名和user_invite。就像这个网站一样,我使用积分系统来鼓励勤奋的用户。下面显示的当前查询根据相关用户添加赞成票和反对票:$creator。我想计算邀请表中同一用户的条目数,并将它找到的每一行添加 50 到我的查询的当前输出/总和中。是否可以通过一个查询实现这一点,还是需要两个查询?
"SELECT *,
SUM(IF(points_id = \"1\", 1,0))-SUM(IF(points_id = \"2\", 1,0)) AS 'total'
FROM points
LEFT JOIN post ON post.post_id=points.points_id
WHERE post.creator='$creator'"
最佳答案
这应该有效:
SELECT *,**SUM(IF(points_id = "1", 1,0))-SUM(IF(points_id = "2", 1,0))+(select count(*)*50
from inivite where username='$creator') AS 'total'**,
FROM points LEFT JOIN post ON post.post_id=points.points_id WHERE post.creator='$creator'"
关于mysql - 谁能帮我完成一个复杂的 sum、3 个表连接 mysql 查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2550500/