我有一个带有列" user"的MySQL表。和#34;警告点"对于每个警告,您可以在上表中看到。如何在PHP中获得总共警告点最多的用户?
答案 0 :(得分:0)
您可以使用GROUP BY
和ORDER BY
以及LIMIT
:
SELECT t.user,sum(t.warningPoints) as sum_points
FROM YourTable t
GROUP BY t.user
ORDER BY sum_points DESC
LIMIT 1;
或者,如果每人只有一条记录,则无需分组:
SELECT t.user,t.warningPoints
FROM YourTable t
ORDER BY t.warningPoints DESC
LIMIT 1;
答案 1 :(得分:0)
您可以在php代码中添加以下语句。
$sql = "SELECT User, Max(warningpoints) AS MaxWarningpoints FROM MyGuests GROUP BY User";
$result = $conn->query($sql);