title: SQL : Group By on range of dynamic values
body: <p>This is similar to some other questions here, but those use a CASE which I cannot. This is on Oracle, and I will be running the query from an excel sheet. (And by the way these do not support WITH, which makes life much harder)</p>
  
  <p>I have a range of dates in one big table - like 1/3/2011, 4/5/2012, 7/1/2013, 9/1/2013.....
  Then I have another table with hours worked by employees on certain dates. So what I need to do is get a sum of number of hours worked by each employee in each intervening time period. So the tables are like</p>
  
  <pre><code>Dates
  1-May-2011
  5-Aug-2011 
  4-Apr-2012
  ....
  </code></pre>
  
  <p>and another</p>
  
  <pre><code>Employee   Hours   Date
  Sam        4       1-Jan-2011
  Sam        7       5-Jan-2011
  Mary       12      7-Jan-2012
  Mary       5       12-Dec-2013
  ......
  </code></pre>
  
  <p>so the result should be</p>
  
  <pre><code>Employee  Hours   In Date Range Till
  Sam       11      1-May-2011
  Sam       0       5-Aug-2011
  Sam       0       4-Apr-2012
  Mary      0       1-May-2011
  Mary      0       5-Aug-2011
  Mary      12      4-Apr-2012
  ....
  </code></pre>
  
  <p>Any pointers on how to achieve this please?</p>