Table structure:
uid : integer
answer_id : integer
I need to run a query which will show me which uid’s have the same answers as other uid’s. So for example, here’s some test data:
answer_id uid
1 555
4 555
7 555
10 555
1 123
5 123
7 123
10 123
So we can see from this data that they each answered 3/4 of the questions the same way.
I’m struggling with how to write a query which would show me which uid’s match 3/4 or 4/4 of the same answers. Basically I’m trying to find users with 75% (3/4) or greater (4/4) similar answers.
This is part of a Ruby on Rails application, so I have the models all built [User, UserAnswers etc..] but I’m assuming this will just be a SQL query, not necessarily a part of ActiveRecord
This query show the number of answers every user has in common with each other:
This also shows the number of questions each user has answered:
(this second query can be very slow)