0
当满足以下条件时,下面的查询从MySQL表“comment”中总结points
:修改具有左连接和内连接的查询
找到
l.username = '$profile'
时的loginid
。发现所有
submissionid
都有上面#1的loginid
。找到所有
commentid
与上面#2的submissionid
s,并将相应的points
相加。
现在,我怎么能做出一个不同的查询来返回上面#3中所有comment
的数组而不是总结point
?
这里所涉及的MySQL表:
登录:
logind username created activated
提交:
submissionid loginid
评论:
commentid submissionid points comment
查询:
SELECT
l.loginid,
l.username,
l.created,
l.activated,
COALESCE(scs.total, 0) AS commentsreceivedvalue
FROM login l
LEFT JOIN (
SELECT S2.loginid, SUM(C2.points) AS total
FROM submission S2
INNER JOIN comment C2
ON S2.submissionid = C2.submissionid
GROUP BY S2.loginid
) scs ON scs.loginid = l.loginid
WHERE l.activated = 1
AND l.username = '$profile'
GROUP BY l.loginid
ORDER BY commentsreceivedvalue DESC