假设您有一个这样的表:
id user score
这是用户分数的转储,其中每个user
可以有N score
个。
如何为每位用户选择最高分?
答案 0 :(得分:4)
SELECT user,max(score)
FROM mytable
GROUP BY user
答案 1 :(得分:3)
select user, max(score) as HighScore
from table
group by user
order by max(score);
那应该能满足你的需求。
修改强> 添加了语句终止符
答案 2 :(得分:1)
SELECT user, MAX(score) FROM [TABLE] GROUP BY user
答案 3 :(得分:-1)
MAX(得分)的替代方法是使用PHP迭代得分列表并选择最高。
while ( $curUser = mysql_fetch_assoc($userQry) ) {
$highest = 0;
$scores = explode(',',$curUser["score"]);
foreach($scores as $score){
if ($highest < $score)
$highest = $score;
}
}