title: Group by middle node in gremlin
body: <p>All</p>
  
  <p>I am doing Rank of Neighbors problem using <code>gremlin</code>.<br>
  Here is the details of this problem:<br>
  Rank of neighbors (SQ : Ranking)<br>
  Given a start node v and two edge types Ei and Ej, return k neighbors of v with the
  edge type Ei with the highest number of out-going edges of edge type Ej .
  For instance, list k friends of a given person ranked by the number of sports each friend
  plays.<br>
  Here is my code in gremlin:
  <code>g.V().has('unique1',1220).out('relation1').as('a').out('relation2').as('b').select('a','b')</code>
  I am trying to group the results by nodes marked by 'a', and then return some properties and the number of each group as the results.<br>
  For example:<br>
  If the graph has the relationships:<br></p>
  
  <pre><code>a-&gt;b-&gt;c&lt;br&gt;
  a-&gt;b-&gt;d&lt;br&gt;
  a-&gt;e-&gt;f&lt;br&gt;
  a-&gt;e-&gt;g&lt;br&gt;
  </code></pre>
  
  <p>Ideally, the result I want should be:<br>
  b:2<br>
  e:2<br>
  How can I revise my query to get the correct result.
  And if it is possible, how can I get the result in descending order of the number.<br></p>
  
  <p>Thanks for your help!</p>