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