COUNT
The COUNT
-operation lets you, as the name suggests, count specified items in the graph. In order to get the sum of all novels in the MiMoText graph written by Tiphaigne de la Roche, you can change your SELECT
-part of the query to SELECT (count(?item) as ?count)
.
The variable in brackets of COUNT represents the item you want to sum up; the variable behind the AS
will be shown as a new column in the results table.
Example: Get the count of the novels written by Tiphaigne de la Roche
In this case you only want to count the novels of one author; if you want to query how many novels all the authors have written, you have to add a GROUP BY
operation at the end of your query. The GROUP BY
variable needs to be the same as the one in the COUNT
-operation.
You can add ORDER BY DESC (?count)
if the results should be ordered descending by the count.
Example: Get the count of written novels per author
To get all authors that have written more than 10 novels, you can add HAVING (count(?authorName) > 10)
after the GROUP BY
-operation; if you still want to see the count-result you should leave the COUNT
in the SELECT
-part.
Example: Get the authors with more than 10 novels
COUNT
: Count is a SPARQL set function which counts the number of times a given expression has a bound, and non-error value within the aggregate group.