SQL Simple Join Query
<p>I start by saying that I am new to SQL so the question may be trivial.
I have two tables with a time-stamp key.
For each event <code>t_i</code> in <code>table 1</code> I want all the events <code>q</code> in <code>table 2</code> such that :</p>

<pre><code>q.timeStamp &lt; t_i.timeStamp and q.timeStamp &gt; t_{i-1}.timeStamp
</code></pre>

<p>That is to say, if events happen according to time stamp in this order: </p>

<pre><code>    q1
t1  q2
    q3
    q4
t2  q5
    q6
t3  q7
</code></pre>

<p>then the resulting query should be:</p>

<pre><code>t1: q1
t2: q2 q3 q4
t3: q5 q6
</code></pre>

<p>I am using Scala with SQL Spark with DataSet and DataFrame classes, so either a pure functional 'groupBy' or a SQL query would be good.</p>