select p.*, count(pt.id) similar_tags_count
from posts p
inner join posts_tags pt on pt.post_id = p.id and pt.tag_id in (select tag_id from posts_tags where post_id = 1) #id текущего поста
where p.id != 1 #id текущего поста
group by p.id
order by count(pt.id) desc