title: MySQL: have internal query reference external column on same table
body: <p>I have a table that looks like this</p>
  
  <pre><code>id | startTime           | endTime
  1  | 2012-11-07 12:33:23 | 2012-11-07 12:44:44
  3  | 2012-11-07 12:45:55 | 2012-11-07 12:48:43
  9  | 2012-11-07 12:47:23 | 2012-11-07 13:00:00
  13 | 2012-11-08 12:32:22 | 2012-11-08 13:00:00
  </code></pre>
  
  <p>How can I write a query that returns me</p>
  
  <pre><code>id | CountNumIDsBeforeThisIDOnSameDay | CountNumIDsThatEndedBeforeThisIDOnSameDay
  1  | 0                                | 0
  3  | 1                                | 1
  9  | 2                                | 1
  13 | 0                                | 0
  </code></pre>
  
  <p><strong>Other assumptions</strong></p>
  
  <p>id may not be in running number</p>
  
  <p>I am not sure how to phrase what I am thinking in an easy manner. But basically, I know I can get the counts easily if I can reference the current row ID in my sub-query. I was also thinking of using <code>LEFT OUTER JOINS</code> but I am not sure if I am complicating things myself.</p>