How to find the number of months missing from January to July of a Year in MySQL
<p>i have a View named view_uncollected.</p>

<pre><code>|RemitNo|ID|Employer|  AP_From |  AP_To   |Amount|
|   1   |1 |    a   |2016-01-01|2016-01-31|200.00|
|   2   |1 |    a   |2016-02-01|2016-02-29|200.00|
|   3   |1 |    a   |2016-03-01|2016-03-31|200.00|
|   4   |1 |    a   |2016-04-01|2016-05-31|400.00|
|   5   |1 |    a   |2016-06-01|2016-06-30|200.00|
|   6   |2 |    b   |2016-01-01|2016-03-31|600.00|
|   7   |2 |    b   |2016-04-01|2016-04-30|200.00|
|   8   |2 |    b   |2016-05-01|2016-05-31|200.00|
|   9   |3 |    c   |2016-01-01|2016-01-31|200.00|
|  10   |3 |    c   |2016-01-01|2016-01-31|200.00|
|  11   |3 |    c   |2016-03-01|2016-03-31|200.00|
</code></pre>

<p>I need to find how many MONTHS is missing from January - July of 2016. </p>

<p>Based on the table above there are some complex cases:</p>

<ul>
<li>Employer(a) paid from January - June 2016 ONLY. One month is missing from it. </li>
<li>Employer(b) paid from January - May 2016 ONLY. 2 months is missing from it.</li>
<li>Employer(c) paid January (2x) and March. 5 months is missing from it. <em>We will not consider the other Payment of January as February.</em> </li>
</ul>

<p>How can i count the months missing from each employer?</p>

<p>What I did is use this <code>7 - COUNT(RemitNo) GROUP BY ID</code> because i thought that each <code>ONE ROW = ONE MONTH</code> . but after reviewing my results, some employers have <code>ONE ROW = 2 MONTHS</code>, like <code>RemitNo = 4</code>. I knew then that is was wrong because it only counts the number of rows not the number of months. </p>

<p>The reason behind this is that we need to know how much remittance is uncollected from January to July of 2016.</p>

<p>Thank you for the suggestions and comments. Sorry for this novice question</p>