title: Count Distinct over partition by sql
body: <p>I have a table like</p>
  
  <pre><code>col1ID  col2String Col3ID Col4String Col5Data
    1        xxx       20      abc     14-09-2018
    1        xxx       20      xyz     14-09-2018
    2        xxx       30      abc     14-09-2018
    2        xxx       30      abc     14-09-2018 
  </code></pre>
  
  <p>I would like to add column which count how many different strings I have in col4String group by col1ID and col3ID.</p>
  
  <p>So something like</p>
  
  <pre><code>COUNT(DISTINCT (Col4String)) over (partition by col1ID, col3ID)
  </code></pre>
  
  <p>but it doesn't work, I receive an error</p>
  
  <blockquote>
    <p>Use of DISTINCT is not allowed with the OVER clause. <br>
        Msg 102, Level 15, State 1, Line 23.</p>
  </blockquote>
  
  <p>I have more columns like col2String, col5Data but they shouldn´t be affected, so I can't use distinct at the beginning of <code>SELECT</code>, and <code>dense_rank()</code> also doen´t seems to work in my case.</p>
  
  <p>Thank You for help.</p>