Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have gathered top 10 users for specific task. Using the query given below.

$sqlsum=mysql_query("SELECT `userid`, SUM(`points`) as `total` FROM 
    `tablename` GROUP BY `userid` ORDER BY total DESC LIMIT 10");

Now , I need to award bonues to the top 10 gathered users only. I am not getting the idea , on how to write query for this purpose.

I need to update one field in tablename = user , field name = bonus .

Kindly guide.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
420 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use a JOIN for this purpose like

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...