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
base code
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:
HAVING (?tw > 3)
is correct SPARQL.HAVING
filters after assignments due toSELECT
, so?tw
is visible, and before projection.where
?.0
is the assignment ofcount
.Using HAVING
In addition to AKSW's answer — https://github.com/openlink/virtuoso-opensource/issues/254.
Using FILTER
You should write something like that: