开发者

get average of last three entries for each user

I need a query that will show the average of the last three entries for each user, then display these averages from highest to lowest

I can extract this for a specific user using:

SELECT x.`cf_user开发者_如何学Python_id` , AVG( x.`text_2` )
FROM 
(SELECT t.`cf_user_id` , t.`text_2`
FROM `jos_chronoforms_skills_drawback` t
WHERE t.`cf_user_id` = 62
ORDER BY t.`cf_id` DESC
LIMIT 3) x
GROUP BY x.`cf_user_id` 

But I need this for each user.

Thanx a ton for your help

Mark


Your sql has a WHERE clause identifying a specific user. If you want this for all users, remove your WHERE clause

SELECT x.`cf_user_id` , AVG( x.`text_2` )
FROM 
(
    SELECT t.`cf_user_id` , t.`text_2`
    FROM `jos_chronoforms_skills_drawback` t
    ORDER BY t.`cf_id` DESC
    LIMIT 3
) x
GROUP BY x.`cf_user_id` 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜