title: SQL Server: how to do 3 months' partition?
body: <p>I want to count the number of rows in the partition 0-3months. Months are specified by MYMONTH in the format such that <code>201601</code> for 2016 January. I am using SQL Server 2014. How can I do the partition over 3 months?</p>
  
  <pre><code>SELECT  COUNT(*), 
          COUNT(*)
             /  
          (COUNT(*) OVER (PARTITION 
              BY MYMONTH RANGE BETWEEN  3 MONTH PRECEDING AND CURRENT MONTH))
  FROM myData
  </code></pre>
  
  <p><strong>Sample</strong></p>
  
  <pre><code>|  Month  | Value  |  ID |
  -------------------------|
  | 201601  |   1    |  X  |
  | 201601  |   1    |  Y  |
  | 201601  |   1    |  Y  |
  | 201602  |   1    |  Z  |
  | 201603  |   1    |  A  |
  | 201604  |   1    |  B  |
  | 201605  |   1    |  C  |
  | 201607  |   1    |  E  |
  | 201607  |   10   |  EE |
  | 201607  |   100  |  EEE|
  </code></pre>
  
  <p><strong>Counts</strong></p>
  
  <pre><code>| Month | Count | Count3M | Count/Count3M |
  -------------------------------------------
  | 201601|   3   |    3    |     3/3       |
  | 201602|   1   |    4    |     1/4       |
  | 201603|   1   |    5    |     1/5       |
  | 201604|   1   |    6    |     1/6       |
  | 201605|   1   |    4    |     1/4       |
  | 201607|   3   |    5    |     3/5       |
  </code></pre>