SELECT p.username, COUNT(*) AS like_count
FROM xf_liked_content AS lc
INNER JOIN xf_post AS p ON
(lc.content_type = 'post' AND lc.content_id = p.post_id)
WHERE p.message_state = 'visible'
AND p.thread_id = 9999
GROUP BY lc.content_user_id
ORDER BY like_count DESC