title: SQL server, how to get a number of distinct items
body: <p>I am using SQL server, </p>
  
  <pre><code>  id          3     | 4    | 5 | 6
    items       1 2 3 | 2 3 5| 6 | 1 2 5
      -------------------------
    # of items      3 | 4    | 5 | 5
  </code></pre>
  
  <p>so, each id has items (ex, 3 has 3 items - 1,2,3)
  and for each item, I'd like to get the number of distinct items accrued.</p>
  
  <p>so, 3 has 3 distinct items - 1, 2, 3<br>
  4 has 4 distinct items - 1, 2, 3, 5<br>
  5 has 5 distinc items - 1, 2, 3, 5, 6<br>
  6 has 5 distinct items - 1, 2, 3, 5, 6   </p>
  
  <p>I can do this by running, 1 through 2, 1 though 3, 1 through 5 and 1 through 6 by doing count(distinct items)
  But I want to automate this process and get the same results in one run.</p>
  
  <p>The idea is to create a temp table and put an item in it while checking if the item is already in the temp table and print number of distinct items for each id.  </p>