I am trying to get list of all the authors who have had 3 or more piece of work done (in DBpedia).
my example can be run on : http://dbpedia.org/sparql
select (count(?work) as ?totalWork), ?author
Where
{
?work dbo:author ?author.
}
GROUP BY ?author
I get each authors total amount of piece of work done. But when I try to filter to show only list of author that have more than 3 piece of work. I get error:
I tried HAVING keyword or using FILTER keyword.
Using Filter
select (count(?work) as ?tw), ?author
Where
{
?work dbo:author ?author.
FILTER (?work > 3).
}
GROUP BY ?author
error: Virtuoso 22023 Error VECDT: SR066: Unsupported case in CONVERT (INTEGER -> IRI_ID)
Using HAVING keyword
select (count(?work) as ?tw), ?author
Where
{
?work dbo:author ?author.
}
GROUP BY ?author
HAVING (?tw > 3)
Virtuoso 37000 Error SP031: SPARQL compiler: Variable ?tw is used in the result set outside aggregate and not mentioned in GROUP BY clause
Using HAVING
is correct, but there is a limitation in SPARQL with indirectly referring to aggregates.
This one works:
SELECT (count(?work) as ?tw) ?author
WHERE
{
?work dbo:author ?author.
}
GROUP BY ?author
HAVING (count(?work) > 3)