sql - find similarity of merchant with customers -


i have table in sql server 2012 have columns: user_id , merchant_id

i want find top 5 similar partners each merchant. similarity defined normalized number of overlapping costumers;

i can not find solution problem.

the following query counts number of common customers 2 merchants:

select t.merchantid m1, t2.merchantid m2, count(*) common_customers table t join      table t2      on t.customerid = t2.customerid , t.merchantid <> t2.merchantid group t.merchantid, t2.merchantid; 

the following gets 5 based on raw couns:

select * (select t.merchantid m1, t2.merchantid m2, count(*) common_customers,              row_number() on (partition t.merchantid order count(*) desc) seqnum       table t join            table t2            on t.customerid = t2.customerid , t.merchantid <> t2.merchantid       group t.merchantid, t2.merchantid      ) mm seqnum <= 5; 

i not know mean "normalized". term "normalized" in statistics not change ordering of values (but result in sum of squares being 1), may want.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -