我正在尝试获取所有已完成3项或更多工作的作者的列表(在DBpedia中)。
我的示例可以在http://dbpedia.org/sparql
上运行select (count(?work) as ?totalWork), ?author
Where
{
?work dbo:author ?author.
}
GROUP BY ?author
我得到每个作者完成的工作总量。但是当我尝试过滤以仅显示具有超过3件作品的作者列表时。我收到错误:
我尝试了HAVING关键字或使用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)
使用HAVING关键字
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
答案 0 :(得分:3)
使用HAVING
是正确的,但有一个limitation in SPARQL with indirectly referring to aggregates。
这个有效:
SELECT (count(?work) as ?tw) ?author
WHERE
{
?work dbo:author ?author.
}
GROUP BY ?author
HAVING (count(?work) > 3)
答案 1 :(得分:1)
HAVING (?tw > 3)
是正确的SPARQL。由于HAVING
而导致分配后SELECT
过滤,因此?tw
可见,并且在投影之前。
(prefix ((dbo: <http://purl.org/dc/elements/1.1/>))
(project (?tw ?author)
(filter (> ?tw 3)
(extend ((?tw ?.0))
(group (?author) ((?.0 (count ?work)))
(bgp (triple ?work dbo:author ?author)))))))
其中?.0
是count
的分配。