title: Gremlin query group by clause
body: <p>I am using neptune graph database. Need help writing a query with a group by clause.</p>
  <p>We have three nodes</p>
  <p>CAMPAIGN → AD → LP</p>
  <p>Campaign to Ad is 1 to many mapping
  AD to LP is 1 to 1 mapping</p>
  <p>Suppose we have the following vertices and associations</p>
  <pre><code>C1 → A1 → LP1
  C1 → A2 → LP1
  C2 → A3 → LP1
  C2 → A4 → LP1
  C3 → A5 → LP2
  </code></pre>
  <p>I want my result set to look like this.</p>
  <pre><code>[
     {
          &quot;lp&quot;: &quot;LP1&quot;,
          &quot;campaigns&quot;: [
                  {aId: &quot;A1&quot;, cId: &quot;C1&quot;},
                  {aId: &quot;A2&quot;, cId: &quot;C1&quot;},
                  {aId: &quot;A3&quot;, cId: &quot;C2&quot;},
                  {aId: &quot;A4&quot;, cId: &quot;C2&quot;}
           ]
     },
     {
          &quot;lp&quot;: &quot;LP2&quot;,
          &quot;campaigns&quot;: [
              {aId: &quot;A5&quot;, cId: &quot;C3&quot;}
          ]
     }
  ]
  </code></pre>
  <p>Any help would be greatly appreciated.</p>