tsql में आप निम्न कार्य करेंगे, मुझे आशा है कि यह आपको सही दिशा में ले जाएगा
SELECT
p.id,
c.postcount
FROM posts as p
INNER JOIN (
SELECT
post_id,
count(*) AS postcount
FROM comments
GROUP BY post_id
) as c
on p.id = c.post_id
Order by c.postcount desc