title: postgresql how to group by and then get the first_time and the last_time,
body: <pre><code>event     event_time           arrival_time
  7333 | 2018-09-09       | 2018-10-09
  7444 | 2018-09-10       | 2018-11-09
  7333 | 2018-09-11       | 2018-09-09
  7555 | 2018-09-12       | 2018-08-09
  7555 | 2018-09-13       | 2018-06-09
  7333 | 2018-09-15       | 2018-09-09
  </code></pre>
  
  <p>then I want get the result, in my mind, we want to get the group，then every group show the first event time and the last event time </p>
  
  <pre><code>event event_first       arrival_first      event_last     arrival_last
  7333 | 2018-09-09       | 2018-08-09       | 2018-09-15  |2018-10-09
  7444 | 2018-09-10       | 2018-11-09       | 2018-09-10  |2018-11-09
  7555 | 2018-09-12       | 2018-06-09       | 2018-09-13  |2018-08-09
  </code></pre>
  
  <p>had try this command:</p>
  
  <pre><code>SELECT DISTINCT ON (event)
          event, event_time as event_first, event_time as event_last, arrival_time as arrival_first, arrival_time as arrvial_last
  FROM   A
  ORDER  BY event, event_first, event_last DESC, arrival_first, arrvial_last DESC
  </code></pre>
  
  <p>but it can not work.</p>