title: Different grouping for same elements by orders in HANA SQL
body: <p>I have a table like this:</p>
  
  <pre><code>     NanoTime            Sensor   Key   Rank
  15,899,129,832,916     Gyroscope   i     1
  15,899,132,632,874     Gyroscope   i     2
  15,899,152,377,999     Gyroscope   i     3
  15,900,080,214,835     Gyroscope   o     1
  15,900,092,388,626     Gyroscope   o     2
  15,900,112,529,501     Gyroscope   o     3
  15,971,592,577,285     Gyroscope   i     4
  15,971,592,739,660     Gyroscope   i     5
  15,971,612,339,952     Gyroscope   i     6
  15,971,632,305,202     Gyroscope   i     7
  15,972,579,736,201     Gyroscope   o     4
  15,972,592,583,743     Gyroscope   o     5
  15,972,612,371,701     Gyroscope   o     6
  </code></pre>
  
  <p>The code I used for creating the "Rank" column was:</p>
  
  <pre><code>SELECT "NanoTime","Sensor", "Key",
      ROW_NUMBER() OVER ( PARTITION BY "Sensor", "Key" ORDER BY "NanoTime" ASC) as RANK
  FROM TEST
  WHERE "Sensor" = 'Gyroscope'
  GROUP BY "NanoTime","Sensor", "Key"
  </code></pre>
  
  <p>I want to create a table which the ranks are sorted by "batch" and also include a "Group" column to separate each session (one session contains all the elements with the same "Key") like the one below. </p>
  
  <p>Can you help me with it? Thank you!</p>
  
  <pre><code>     NanoTime            Sensor   Key   Rank    Group
  15,899,129,832,916     Gyroscope   i     1       1
  15,899,132,632,874     Gyroscope   i     2       1
  15,899,152,377,999     Gyroscope   i     3       1
  15,900,080,214,835     Gyroscope   o     1       2
  15,900,092,388,626     Gyroscope   o     2       2
  15,900,112,529,501     Gyroscope   o     3       2
  15,971,592,577,285     Gyroscope   i     1       3
  15,971,592,739,660     Gyroscope   i     2       3
  15,971,612,339,952     Gyroscope   i     3       3
  15,971,632,305,202     Gyroscope   i     4       3
  15,972,579,736,201     Gyroscope   o     1       4
  15,972,592,583,743     Gyroscope   o     2       4
  15,972,612,371,701     Gyroscope   o     3       4
  </code></pre>