title: SQL month to day average (auto)
body: <p>How to count the day for average use in SQL?</p>
  
  <p>for example, I can use today()-20171001 to count it is 22 for average use in excel which it is automatic.</p>
  
  <p>I need count the average value of the computer in Oct-2017 to day.</p>
  
  <p>table: computer data</p>
  
  <pre><code>date       |    property   |    computer code | value
  ----------      --------        -----------    -------
  20160131   |   companyA   |     256584        | 1,000
  20160131   |   companyB   |     987451        | 1,200
  ...
  20171022   |   companyA   |     157489        | 1,600
  20171022   |   companyA   |     589741        | 1,400
  20171022   |   comapnyA   |     547182        | 2,750
  </code></pre>
  
  <p>sql:</p>
  
  <pre><code>select property
  ,sum (case when  property = 'companyA' then value end) / ( the code I have asked - the answer should be 22, 20171023-20171001) as avgvalue_computer
  
  from computer table
  
  group by property
  order by property
  </code></pre>
  
  <hr>
  
  <p>the result I wanted</p>
  
  <pre><code>property | avgvalue_computer
  companyA | 8,500         &lt;- 2017-Oct-01 to 2017-Oct-23 (today)
  companyB | 16,800        &lt;- 2017-Oct-01 to 2017-Oct-23 (today)
  </code></pre>