In general, the query receiving the similarity of users looks something like this:
select * from ( select a.user_id a_user_id,b.user_id b_user_id,a.tcnt a_cnt,b.tcnt b_cnt,count(1) same_cnt from (select user_id,tag_id,count(1) over(partition by user_id) as tcnt from user_tags where user_id=NNN ) A, (select user_id,tag_id,count(1) over(partition by user_id) as tcnt from user_tags ) B where A.tag_id=B.tag_id and A.user_id!=B.user_id group by A.user_id,B.user_id,A.tcnt,B.tcnt ) T where a_cnt=b_cnt and same_cnt=a_cnt
In this example, all completely identical users are obtained. To find similarity, you need to fix where at the very end, based on the fact that a_cnt is the number of tags for user A, b_cnt is for user B, and same_cnt is the number of matching tags. If you want to look for the similarity of a particular user, then it is best to add where user_id=NNN
inside subquery A
If you really want to look for the similarity of all users to all users, then the request can be simplified to speed up the work:
with Q as( select user_id,tag_id,count(1) over(partition by user_id) as tcnt from user_tags ) select a.user_id a_user_id,b.user_id b_user_id,a.tcnt a_cnt,b.tcnt b_cnt,count(1) same_cnt from Q a, Q b where a.tag_id=b.tag_id and b.user_id!=a.user_id group by a.user_id,b.user_id,a.tcnt,b.tcnt having a.tcnt=b.tcnt and a.tcnt=count(1)