title: SQL division by a time frame
body: <p>Have an RDB with a quantity x and the date that quantity started being tracked, date_1 and the date it was finished being tracked date_2.  If tracking is still on going that second date is NULL obviously.</p>
  
  <p>What I would like to do is take the number X and get its average over either date_1 and date_2.  And if date_2 is NULL then go by current time.   Any help?</p>
  
  <p>[EDIT] to clarify in RDB format, one row with data column (x), data column (date_1) and data column (data_2) along with other fields of importance.</p>
  
  <p>[EDIT] so imagine X as some integer like 100,000 and dates being March 30, 2016 12:29:45 and April 3, 2016 03:42:29.  Not sure how to breakdown the date/times yet so open to suggestions.  The end goal is calculate how much of x can be allocated in one month vs how much in the other month.  Depending on how fine grain you breakdown the time frame (days vs seconds) will ultimately change those numbers.</p>