title: T-SQL - Employee Annual Average
body: <p>I'm trying to make an annual average of employees, in a year.</p>
  
  <p>The table 'a' is thus constructed:</p>
  
  <pre><code>CREATE TABLE [dbo]. [A] 
  (
      [id] [INT] NOT NULL,
      [start] [DATETIME] NOT NULL,
      [end] [DATETIME] NOT NULL,
      [employee_code] [INT] NOT NULL
  )
  
  1 - 01/01/2016 - 03/31/2019 - 56
  2 - 01/01/1995 - 06/06/2017 - 13
  -
  -
  </code></pre>
  
  <p>If I simply count the [employee_code] between 01/01/2017 and 12/31/2017 the calculation is incorrect as it does not make a monthly average.</p>
  
  <p>Can you help me? (the correct calculation is to have 12 records indicating the monthly number and at the end divided by 12)</p>
  
  <p>I can't do everything with a T-SQL command.</p>
  
  <p>Can you help me?</p>
  
  <hr>
  
  <p>hello thanks, yes, that's what I was.
  Only one thing, in the query result there are the following records:</p>
  
  <pre><code>1995 1 0 NULL
  1995 2 0 NULL
  1995 3 0 NULL
  1995 4 0 NULL
  1995 5 6 NULL
  1995 6 6 NULL
  1995 7 10 NULL
  1995 8 10 NULL
  1995 9 10 NULL
  1995 10 12 NULL
  1995 11 12 NULL
  1995 12 12 NULL
  NULL 78 1995 6.500000
  </code></pre>
  
  <p>The initial data from which I started are:</p>
  
  <pre><code>03/04/1995 10/20/2005 4
  03/04/1995 19/06/2016 2
  03/04/1995 12/15/2016 2847
  03/04/1995            1
  03/04/1995            5
  03/04/1995            3
  02/06/1995 03/07/2009 9
  02/06/1995            8
  02/06/1995            7
  02/06/1995            6
  09/15/1995 16/05/2017 34
  09/15/1995            33
  </code></pre>
  
  <p>why are the 6 "ecodes" in May and not April?</p>