我收集了前十名用户的特定任务。使用下面给出的查询。
$sqlsum=mysql_query("SELECT `userid`, SUM(`points`) as `total` FROM
`tablename` GROUP BY `userid` ORDER BY total DESC LIMIT 10");
现在,我需要向前十名聚集用户颁发奖金。我不知道如何为此目的编写查询。
我需要更新tablename = user,field name = bonus。
中的一个字段请指导。
答案 0 :(得分:1)
您可以尝试:
$query = "UPDATE user
SET bonus=$some_bonus
WHERE id IN (
SELECT userid from (select userid,sum(points) as total
FROM table_name GROUP BY userid ORDER BY total DESC LIMIT 10))";
这里id是给用户的用户表的id,$ some_bonus将是你想要奖励给前10名用户的奖励。
答案 1 :(得分:0)
您可以将JOIN
用于此目的,例如
UPDATE `tablename` a
JOIN
(
SELECT `userid`, SUM(`points`) as `total` FROM
`tablename` GROUP BY `userid` ORDER BY total DESC LIMIT 10
) tab ON a.`userid` = tab.`userid`
set a.Bonus = 2000