How can I include aggregate function values as objects in SPARQL CONSTRUCT queries?
For a CONSTRUCT query, the aggregate function must be called as part of a subquery in the CONSTRUCT's WHERE clause.
For example, starting with this SPARQL SELECT query --
SELECT DISTINCT ?category
COUNT(?category) AS ?count
WHERE
{
?s <http://purl.org/dc/terms/subject> ?category
FILTER (
?s =<http://dbpedia.org/resource/Higgs_boson>
||
?s =<http://dbpedia.org/resource/Gluon>
)
}
The CONSTRUCT query would be --
CONSTRUCT
{
?category a <http://www.w3.org/2004/02/skos/core#Concept> .
?category <http://www.turnguard.com/virtuoso/aggregates#count> ?count
}
WHERE
{
{
SELECT DISTINCT ?category
COUNT(?category) AS ?count
WHERE
{
?s <http://purl.org/dc/terms/subject> ?category
FILTER (
?s =<http://dbpedia.org/resource/Higgs_boson>
||
?s =<http://dbpedia.org/resource/Gluon>
)
}
}
}
View the results of the query execution on the LOD instance.