title: Build an adjacency list from timeseries data in SQL
body: <p>Let's say I have the following data in a mysql database:</p>
  <p><code>table</code></p>
  <ul>
  <li>timestamp</li>
  <li>event</li>
  <li>session_id</li>
  </ul>
  <p>For example, if the data looks like:</p>
  <pre><code>timestamp                 event         session_id
  2014-01-01 01:01:02       Login         1234
  2014-01-01 01:01:03       Like          1234
  2014-01-01 01:01:05       Logout        1234
  </code></pre>
  <p>To get the results like this:</p>
  <pre><code>session_id       from_event        event            
  1234             null              Login
  1234             Login             Like
  1234             Like              Logout
  </code></pre>
  <p>What I was thinking is to get the events as an ordered array:</p>
  <pre><code>select session_id, group_concat(event order by timestamp) 
  from table 
  group by session_id
  </code></pre>
  <p>But from there not sure how I would build the adjacency list (in sql).</p>