0
我在頁面上運行下面的查詢,其中有一個名爲$u
的會話變量。我想從下面的查詢中創建一個變量$points
等於totalScore2
,其中l.username
等於$u
。字段l.username
將僅等於$u
一次。創建一個等於加入查詢結果的新變量
我該怎麼做?
由於提前,
約翰
$sqlStr5 = "SELECT
l.loginid,
l.username,
l.created,
DATEDIFF(NOW(), l.created) + COALESCE(s.total, 0) * 5 + COALESCE(scs.total, 0) * 10 - COALESCE(nscs.total, 0) * 10 + COALESCE(c.total, 0) AS totalScore2
FROM login l
LEFT JOIN (
SELECT loginid, COUNT(1) AS total
FROM submission
GROUP BY loginid
) s ON l.loginid = s.loginid
LEFT JOIN (
SELECT loginid, COUNT(1) AS total
FROM comment
GROUP BY loginid
) c ON l.loginid = c.loginid
LEFT JOIN (
SELECT S2.loginid, COUNT(1) AS total
FROM submission S2
INNER JOIN comment C2
ON C2.submissionid = S2.submissionid
GROUP BY S2.loginid
) scs ON scs.loginid = l.loginid
LEFT JOIN (
SELECT S2.loginid, COUNT(1) AS total
FROM submission S2
INNER JOIN comment C2
ON C2.submissionid = S2.submissionid
AND C2.loginid = S2.loginid
GROUP BY S2.loginid
) nscs ON nscs.loginid = l.loginid
GROUP BY l.loginid
ORDER BY totalScore2 DESC ";