 <p>The generic method would be to use <code>left join</code> and aggregation:</p> <pre><code>select count(distinct d1.user) as NumEvent1, count(distinct d2.user) as NumEvent2, count(distinct d3.user) as NumEvent3 from data d1 left join data d2 on d2.user = d1.user and d2.time &gt; d1.time and d2.event = 'event2' left join data d3 on d3.user = d2.user and d3.time &gt; d2.time and d3.event = 'event3' where d1.event = 'event1' ; </code></pre>