SQL:
SELECT a.category_id AS categoryId, categoryReplyCount, b.rTopicId AS topicId, b.replyId AS replyId, b.rContent AS content, b.rContentStruc AS contentStruc, b.rReplyDate AS replyDate, b.rLastEditDate AS lastEditDate, b.rMemberId AS memberId, b.rMemberName AS memberName, b.rProvinceName AS provinceName FROM ( SELECT A.category_id, A.reply_id, A.is_hq, (SELECT COUNT(*) FROM CategoryReplyRelation WHERE A.category_id=category_id GROUP BY category_id) AS categoryReplyCount FROM CategoryReplyRelation AS A WHERE A.category_id IN ( ? , ? , ? , ? , ? , ? , ? , ? , ? ) AND A.id = (SELECT id FROM CategoryReplyRelation WHERE category_id=A.category_id ORDER BY category_id, is_hq DESC, reply_id DESC LIMIT 1)) a JOIN ClubReply b ON reply_id = b.replyId WHERE rDelete = 0 ORDER BY category_id [arguments: (47372, 47371, 47370, 47369, 47368, 47367, 47366, 47365, 47364)];