题解 | 推荐内容准确的用户平均评分
推荐内容准确的用户平均评分
https://www.nowcoder.com/practice/2dcac73b647247f0aef0b261ed76b47e
# select
# round((sum(t2.score) / count(distinct t1.rec_user)),3) as avg_score
# from
# recommend_tb t1
# left join user_action_tb t2 on t1.rec_user = t2.user_id
# where
# t1.rec_info_l = t2.hobby_l
SELECT
AVG(score) AS avg_score
FROM
(SELECT DISTINCT u.user_id, r.rec_info_l, u.score
FROM user_action_tb u
JOIN recommend_tb r ON u.hobby_l = r.rec_info_l
WHERE u.user_id = r.rec_user) AS distinct_scores;
我认为还是有必要加一个DISTINCT u.user_id, r.rec_info_l, u.score,因为一个用户可能推荐准确多条记录,这时候随机选一条就可以了,所以要对user_id加一个DISTINCT来约束

