title: select min and max values before a particular row per customerID SQL
body: <p>I have a table which has info about visitors to our website.</p>
  
  <p>So it will look like</p>
  
  <p><code>VISITOR_ID EVENT Date Rank</code> ( I already ranked them portioned by event)</p>
  
  <pre><code>Visitor_id  Event       Date    rank
  1           visit       1/1/14  1
  1           purchase    1/2/14  2
  1           visit       1/3/14  3
  1           visit       1/4/14  4
  1           purchase    1/5/14  5
  1           visit       1/6/14  6
  1           visit       1/7/14  7
  1           visit       1/8/14  8
  1           purchase    1/9/14  9
  </code></pre>
  
  <p>I want to find all the min and max visit dates ( so the first and last visit before every purchase every user made)
   before every purchase so the result should have dates</p>
  
  <pre><code>visitor   mindate       maxdate 
  1         1/1/2014      1/1/2014 (in this scenario there was only one visit before a purchase)
  1         1/3/2014      1/4/2014 ( 2 OR MORE VISITS BEFORE A PURCHASE)
  1         1/6/2014      1/8/2014 
  </code></pre>
  
  <p>This is just an example for one visitor. The table has around a million visitors. Please help.</p>