title: SPARQL counting triples in multiple graphs
body: <p>I want to count triples in multiple graphs which are of a certain class and sum it up. I manage to count the triples of this class in each graph but I don't manage to calculate the total.</p>
  
  <p>Initial query:</p>
  
  <pre class="lang-sql prettyprint-override"><code>PREFIX locah: &lt;http://data.archiveshub.ac.uk/def/&gt;
  PREFIX bs: &lt;http://localhost:3030/alod/bs&gt;
  PREFIX ne: &lt;http://localhost:3030/alod/ne&gt;
  
  SELECT (count(?sBS) as ?BScount) (count(?sNE) AS ?NEcount) WHERE {
    {
      GRAPH bs: {
        ?sBS a locah:ArchivalResource
      }
    } UNION {
      GRAPH ne: {
        ?sNE a locah:ArchivalResource
      }
    }
  }    
  </code></pre>
  
  <p>My idea was to simply use the <code>SUM()</code> function as well so the SELECT would be like this:</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT (count(?sBS) as ?BScount) (count(?sNE) AS ?NEcount) (SUM(?NEcount ?BScount) AS ?total )WHERE {
  </code></pre>
  
  <p>But that doesn't seem to work.</p>
  
  <p>And a related question: Why do I need the UNION? If I execute it without UNION it seems to come up with a very high triple count which doesn't make much sense and the count is twice the same.</p>
  
  <p>You can try it on my SPARQL endpoint: <a href="http://data.alod.ch/sparql/?outputFormat=table&amp;query=%0APREFIX+locah%3A+%3Chttp%3A%2F%2Fdata.archiveshub.ac.uk%2Fdef%2F%3E%0APREFIX+bs%3A+%3Chttp%3A%2F%2Flocalhost%3A3030%2Falod%2Fbs%3E%0APREFIX+ne%3A+%3Chttp%3A%2F%2Flocalhost%3A3030%2Falod%2Fne%3E%0A%0ASELECT+(count(%3FsBS)+as+%3FBScount)+(count(%3FsNE)+AS+%3FNEcount)+WHERE+%7B%0A++%7B%0A++++GRAPH+bs%3A+%7B%0A++++++%3FsBS+a+locah%3AArchivalResource%0A++++%7D%0A++%7D+UNION+%7B%0A++++GRAPH+ne%3A+%7B%0A++++++%3FsNE+a+locah%3AArchivalResource%0A++++%7D%0A++%7D%0A%7D&amp;contentTypeConstruct=text%2Fturtle&amp;contentTypeSelect=application%2Fsparql-results%2Bjson&amp;endpoint=http%3A%2F%2Fdata.alod.ch%2Falod%2Fsparql&amp;requestMethod=POST&amp;tabTitle=Query" rel="nofollow">http://data.alod.ch/sparql/</a></p>