我有一個3 SQL表:在上週找到最高投票的問題。 (SQL查詢)
qotwQuestion1a(QuestionId [primarykey], Question, MemberId, PostDate);
qotwVote1a (QuestionId [primarykey], MemberId [primarykey], Vote1a);
qotwMember (MemberId [primarykey], Name, Password, emailId);
我想寫一個sql查詢發現,在上週的最高票的問題的QuetionId和成員Id。我已經用PHP編寫此查詢,但它給了我一個錯誤的結果:
$result6 = mysql_query("SELECT MAX(Vote1a) AS highestVote, * FROM qotwMember, qotwQuestion1a , qotwVote1a
WHERE qotwMember.MemberId=qotwQuestion1a.MemberId
AND qotwQuestion1a.QuestionId=qotwVote1a.QuestionId
AND qotwQuestion1a.MemberId=qotwVote1a.MemberId
AND PostDate>='".$startofweek."' AND PostDate<='".$endofweek."'
ORDER BY qotwQuestion1a.QuestionId DESC ");
while($row6 = mysql_fetch_array($result6))
{
echo "The highest voted question of the last week is: "; echo $row6['highestVote']; echo $row6['MemberId'] . " " . $row6['Name'] . " " . $row6['Password'] . " " . $row6['PostDate'] . " " . $row6['Question']." ".$row6['QuestionId']." ".$row6['Vote1a'];
echo "<br />";
}
的$startofweek
和$endofweek
給上週和上週結束的開始日期。
有人可以幫助我這個,請。
最佳 Zeeshan
您在下面的評論中提到,您希望獲得最高票數的所有問題。你應該在你的問題中提及。 – sangretu 2009-07-20 18:12:36