0

以下代码仅适用于第一个值(puzzle_level==4),它应该做的是打印出puzzle_level==4、5、6和7 :(

    $result = mysql_query("
    SELECT puzzle_level, max(final_score) as highest_final_score
        FROM sleuth_game
        WHERE playerID='$_SESSION[customerID]' and final_score > 1
        GROUP BY puzzle_level
        ORDER BY puzzle_level");  //Load in a the highest scores
    while($row = mysql_fetch_array($result)) {
        echo "<p>".$row['highest_final_score']."</p>";
    }

编辑:在数据库中,所有游戏都是puzzle_level 4、5、6或7。我希望的输出是玩家在每个puzzle_level中获得的最高分,但我编写的代码只显示puzzle_level=的最高分=4。

4

1 回答 1

1

您究竟想在 SQL 查询的 WHERE 语句中使用 'final_score>1' 实现什么?

SELECT puzzle_level, max(final_score) as highest_final_score
FROM sleuth_game
WHERE playerID='$_SESSION[customerID]' and final_score > 1
GROUP BY puzzle_level
ORDER BY puzzle_level

也许 HAVING 子句是您想要实现的解决方案:

SELECT puzzle_level,MAX(final_score) AS highest_final_score
FROM sleuth_game
WHERE playerID='$_SESSION[customerID]'
GROUP BY puzzle_level
HAVING MAX(final_score)>1
ORDER BY puzzle_level
于 2012-09-24T20:38:42.990 回答