0
我有這2個查詢:結合2個查詢一個
$sql = "SELECT SUM(points) as userpoints FROM ".$prefix."_publicpoints
WHERE date BETWEEN ? AND ? AND fk_player_id = ?";
// Getting the users points into a variable to use in the next query
$userPoints;
$getuserplacement = "SELECT fk_player_id FROM ".$prefix."_publicpoints
WHERE date BETWEEN ? AND ?
GROUP BY fk_player_id
HAVING SUM(points) > $userPoints";
// After this I count the rows I get and put that into a variable and thats the users Rank
$userRank = $stmt->num_rows + 1;
這給了我這些數字:點數:-178佈局:1891年
我已經然後試圖通過伊萬的例子:
$sql= "SELECT fk_player_id FROM ".$prefix."_publicpoints
WHERE date BETWEEN ? AND ?
GROUP BY fk_player_id
HAVING SUM(points) > (
SELECT SUM(points) as userpoints FROM ".$prefix."_publicpoints
WHERE date BETWEEN ? AND ? AND fk_player_id = ?
)";
if($stmt->prepare($sql)){
$stmt->bind_param('ssssi',$yearFrom,$yearTo,$yearFrom,$yearTo,$playerid);
$stmt->execute();
$stmt->store_result();
$userMrank = $stmt->num_rows;
if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
$stmt->bind_result($userPoints);
$stmt->fetch();
}
這給了我這些數字:積分:3放置:0
是否有可能這兩個查詢組合成一?
希望能幫忙:-)
編輯後,我不明白你的問題,這是2個查詢? – Ivan 2013-02-09 23:57:44
對不起,再次編輯我的文章: -/ – Mansa 2013-02-10 00:11:38
你爲什麼要合併它們? – 2013-02-10 07:27:13