Is there any way to bind the result of count to a variable? I\'ve tried the following (which doesn\'t work):
COUNT
is an aggregate function and may be used only to define projected variables. To count all matches, your specific example should read:
SELECT ( COUNT(?s) AS ?totalSubject ) WHERE {
?s ?p ?o.
}
However, aggregate functions are usually applied to groups of matches. For instance, to count subjects grouped by type:
SELECT ?t ( COUNT(?s) AS ?totalSubject ) WHERE {
?s a ?t.
} GROUP BY ?t
Be aware that when using aggregate functions your query is subject to some restrictions: selected variables must be either
GROUP BY
; or