我在一个名为$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 ";
答案 0 :(得分:0)
这有效:
$resultp = mysql_query($sqlStr5);
$count = 1;
while($rowp = mysql_fetch_array($resultp))
{
if($u == $rowp['username'])
{
$points = $rowp['totalScore2'];
}
$count++;
}