title: Is it possible to perform an INSERT operation with the GROUP BY clause in SPARQL/Update?
body: <p>Suppose I have a graph containing students from three different grades.</p>
  <p>Sample graph:</p>
  <pre><code>&lt;http://some/graph#John_Doe&gt; rdf:type &lt;http://some/graph/ontology#Student&gt;
  &lt;http://some/graph#John_Doe&gt; &lt;http://some/graph#hasGrade&gt; &lt;http://some/graph#Grade_3&gt;
  &lt;http://some/graph#Grade_3&gt; rdf:type &lt;http://some/graph/ontology#Grade&gt;
  </code></pre>
  <p>I want to create an attribute for every instance of class <em><strong>Grade</strong></em> called <em><strong>gradeStrength</strong></em> to store the number of students in that grade.</p>
  <p>With the above example it would look like:</p>
  <pre><code>&lt;http://some/graph#Grade_3&gt; &lt;http://some/graph#gradeStrength&gt; 1^^xsd:integer
  </code></pre>
  <p>Currently I do it using two separate queries as follows -</p>
  <ol>
  <li>Run a SELECT + GROUP BY query on the graph to get count per grade</li>
  <li>Iterate over the result rows of 1. to create a string of triples</li>
  <li>Run a INSERT DATA update query on the graph</li>
  </ol>
  <p>How can I achieve this by using a single SPARQL/Update query using the INSERT and GROUP BY constructs? I tried writing such a query and it fails in Blazegraph.</p>