SELECT
u.userName,
wt.weapon_type,
AVG(w.rarity) AS avg_rarity
FROM
user u
JOIN
weapon w ON u.weapon_id = w.id
JOIN
weapon_type wt ON w.weapon_type_id = wt.id
GROUP BY
u.userName, wt.weapon_type
ORDER BY
u.userName, avg_rarity DESC;