title: Replace selfjoin with analytic functions
body: <p>How do I go about replacing the following self join using analytics:</p>
  
  <pre><code>SELECT 
  t1.col1 col1,
  t1.col2 col2,
  SUM((extract(hour FROM (t1.times_stamp - t2.times_stamp)) * 3600 + extract(minute FROM ( t1.times_stamp - t2.times_stamp)) * 60 + extract(second FROM ( t1.times_stamp - t2.times_stamp)) ) ) div,
  COUNT(*) tot_count
  FROM tab1 t1,
  tab1 t2
  WHERE t2.col1      = t1.col1
  AND t2.col2  = t1.col2
  AND t2.col3        = t1.sequence_num
  AND t2.times_stamp     &lt; t1.times_stamp
  AND t2.col4         = 3
  AND t1.col4         = 4
  AND t2.col5 NOT IN(103,123)
  AND t1.col5     != 549
  GROUP BY t1.col1, t1.col2
  </code></pre>