title: MySQL COUNT(CASE WHEN ... THEN DISTINCT Column)
body: <p>My query:</p>
  
  <pre><code>COUNT(
      CASE WHEN YEAR(FieldValue) = YEAR(CURDATE()) 
      AND MONTH(FieldValue) = MONTH(CURDATE())
      THEN 1
      END
  ) AS mtd
  </code></pre>
  
  <p>I want something like:</p>
  
  <pre><code>COUNT(
      CASE WHEN YEAR(FieldValue) = YEAR(CURDATE()) 
      AND MONTH(FieldValue) = MONTH(CURDATE())
      THEN DISTINCT ColumnID
      END
  ) AS mtd
  </code></pre>
  
  <p>This gives an error. I can not use <strong>GROUP BY</strong>. If I add DISTINCT before CASE it does not work either it treats FieldValue column as DISTINCT but I want it to count ColumnID as distinct.</p>
  
  <p>Please help</p>