title: How to find unique value in a MySQL Group By query?
body: <blockquote>
    <p><strong>MySQL TABLE :</strong> <code>numbers</code></p>
  </blockquote>
  
  <pre><code>+----+-----+------------+
  | ID | NUM |   CREATED  |
  +----+-----+------------+
  | 1  | 11  | 2018-01-01 |
  +----+-----+------------+
  | 2  | 22  | 2018-02-01 |
  +----+-----+------------+
  | 3  | 11  | 2018-03-01 |
  +----+-----+------------+
  | 4  | 44  | 2018-04-01 |
  +----+-----+------------+
  | 6  | 44  | 2018-04-02 |
  +----+-----+------------+
  | 5  | 22  | 2018-05-01 |
  +----+-----+------------+
  </code></pre>
  
  <p>In this table, <code>ID</code> is the <strong>Primary Key</strong>. <code>NUM</code> is the random value and <code>CREATED</code> is the <strong>Date</strong>.</p>
  
  <blockquote>
    <p><strong>My Query:</strong></p>
  </blockquote>
  
  <pre><code>SELECT
    DATE_FORMAT(CREATED,'%Y-%m') AS Month,
    COUNT(NUM) AS TotalNum,
    COUNT(DISTINCT(NUM)) AS UniqueNum
  FROM
    `numbers`
  GROUP BY
    DATE_FORMAT(CREATED,'%Y-%m')
  </code></pre>
  
  <blockquote>
    <p><strong>Result of My Query:</strong></p>
  </blockquote>
  
  <pre><code>+---------+----------+-----------+
  | Month   | TotalNum | UniqueNum |
  +---------+----------+-----------+
  | 2018-01 |    1     |     1     |
  +---------+----------+-----------+
  | 2018-02 |    1     |     1     |
  +---------+----------+-----------+
  | 2018-03 |    1     |     1     |
  +---------+----------+-----------+
  | 2018-04 |    2     |     1     |
  +---------+----------+-----------+
  | 2018-05 |    1     |     1     |
  +---------+----------+-----------+
  </code></pre>
  
  <blockquote>
    <p><strong>But my Expected Result is :</strong></p>
  </blockquote>
  
  <pre><code>+---------+----------+-----------+
  | Month   | TotalNum | UniqueNum |
  +---------+----------+-----------+
  | 2018-01 |    1     |     1     |
  +---------+----------+-----------+
  | 2018-02 |    1     |     1     |
  +---------+----------+-----------+
  | 2018-03 |    1     |     0     |
  +---------+----------+-----------+
  | 2018-04 |    2     |     1     |
  +---------+----------+-----------+
  | 2018-05 |    1     |     0     |
  +---------+----------+-----------+
  </code></pre>
  
  <p>Result of <code>UniqueNum</code> should be <code>0</code> in Month <strong>2018-03</strong>. Because <code>NUM</code> 11 is already exists in Month <strong>2018-01</strong>. <br/><br/> Also 
  Result of <code>UniqueNum</code> should be <code>0</code> in Month <strong>2018-05</strong> . Because <code>NUM</code> 22 already exists in Month <strong>2018-02</strong>.</p>
  
  <p>I want to find the Unique number for every Month. How can I get my expected result by updating my <strong>MySQL Query</strong>? Please help.</p>