开发者

get average of last three entries for each user

开发者 https://www.devze.com 2023-03-23 11:58 出处:网络
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 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

精彩评论

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

关注公众号