title: SQLite query for n-th day of month
body: <p>Say, I have the following table:</p>
  
  <pre><code>CREATE TABLE Data (
      Id INTEGER PRIMARY KEY,
      Value DECIMAL,
      Date DATE);
  </code></pre>
  
  <p>Since the application is finance-related, user may choose, which day would be the first day of the month. For instance, if he receives salary every 10th of the month, he may set the first day of the month to be 10th.</p>
  
  <p>I'd like to create a query, which returns average value for n-th day of month, as defined by user. For instance:</p>
  
  <pre><code> Date           | Value
   ---------------+------
   10.01.2016     | 10
   11.01.2016     | 15
   10.02.2016     | 20
   11.03.2016     | 10
  </code></pre>
  
  <p>Result of the query should be:</p>
  
  <pre><code> Day | Average
   ----+--------
   1   | 15
   2   | 12.5
  </code></pre>
  
  <p>Note, that if user sets first day to 10th, 9th of the month may be 28th, 29th, 30th or 31st day of a month (depending on which month we're talking about). So this is not as simple as extracting day number from the date.</p>