title: Query to serialize data
body: <p>I have two tables:</p>
  
  <pre>
  Routes
  
  ID   Description
  1    street1
  2    street2
  3    street3
  4    street4
  5    street5
  
  Segments 
  
  ID  RouteID, Progres, LabelStart, LabelEnd
  1   1        5            1 A        21 B
  2   1        10           2 A        10 
  3   2        15           3          25 
  4   2        15           2          20
  5   3        20           1          11 
  6   3        22           4          10
  7   4        30           5          11 
  8   4        31           2          12
  </pre>
  
  <p>I need a sequence with these rules:</p>
  
  <ol>
  <li>table must be ordered by Progress ASC </li>
  <li>A column Type is defined and take O if LabelStart and LabelEnd are Odd, E if Even</li>
  <li>if two routes have the same progress then the rows are merged in one where 
  LabelStart is the minimum (among LabelStart Odd and LabelStart Even) 
  and LabelEnd is the Max, in this case Type takes the value of A (All)</li>
  </ol>
  
  <p>as per example data above the result should be</p>
  
  <pre>
  Sequence  
  ID  RouteID, Progres, LabelStart, LabelEnd  Type
  1   1        5            1 A        21 B    O
  2   1        10           2 A        10      E 
  4   2        15           2          25      A
  5   3        20           1          11      O
  6   3        22           4          10      E
  7   4        30           5          11      O
  8   4        31           2          12      E
  </pre>
  
  <p>It is for Postgres 9.2</p>