title: Find ratio of duplicate values in a field b/w every 2 users. (MySQL)
body: <p>I want to generate a complex report on a single database table (MYSQL) for User_Hits. Here is the table structure with sample data.</p>
  
  <pre><code>    TABLE: User_Hits
  User_ID      IP_Address
  1            192.168.1.1
  1            192.168.1.2
  1            192.168.1.3
  1            192.168.1.4
  2            192.168.1.2
  2            192.168.1.4
  2            192.168.1.50
  2            192.168.1.55
  3            192.168.1.2
  3            192.168.1.55
  3            192.168.1.111
  </code></pre>
  
  <p>And here is the report output I want to get.</p>
  
  <pre><code>Percentage of duplicate IPs b/w every two Users
  
  USER     1        2        3
    1     -       50%      25%
    2     50%       -       50%
    3     33.3%   66.6%      -
  </code></pre>
  
  <p>Values of each cell are based on following example calculation:<br />
  For Example, 66.6% is calculated as:</p>
  
  <pre><code>= (Number of IPs common b/w User 3 and User2) * 100 / (Number of IPs for User3 )
  = (2 * 100) / 3
  = 66.6
  </code></pre>
  
  <p>Every cell in the report is calculated the same way.</p>
  
  <p>Is it possible to generate this report by using MYSQL queries only ?
  Anyone has ever generated this kind of report... Please guide me, I need help from SQL experts.</p>
  
  <p>I have built schema for <strong>User_Hits</strong> in <a href="http://sqlfiddle.com/#!2/213b2/1" rel="nofollow">SQL FIDDLE</a> so you can write query herein directly.</p>
  
  <p>Thanks</p>