php - What kind of algorithm should I use to find similarities in a db? -


let's have 1000 users app. ask them 100 questions answers yes/no , record answers in seperate table.

now, want see people has given same answers @ least 20 questions.

what kind of algorithm should follow in order this? relevant keywords googling?

p.s. work in wamp environment.

join answers table itself, selecting answers share same question_id , answer have different user_id. group rows both user_ids , use having clause exclude less 20 matching answers.

example looking users similar user user_id "1":

select distinct a2.user_id answers inner join answers a2         on a.question_id = a2.question_id        , a.answer = a2.answer        , a.user_id != a2.user_id a.user_id = 1 group a.user_id, a2.user_id having count(*) >= 20; 

technically don't need group a.user_id in case i've left there in case want modify where clause return results more 1 a.user_id.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -