I am struggling to write a SPARQL query to fetch a list of products by the owner along with a count of other owners.
following is the query i expect to get the result
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX schema:<http://schema.org/>
SELECT distinct ?uri ?label ?r ?ownership ?rating ?comments ?allOwners
FROM <http://xxxx.net/>
WHERE {
?r rdf:type <http://schema.org/Relation> .
?r schema:property ?uri.
?r schema:owner ?owner .
?r schema:ownership ?ownership .
?uri rdfs:label ?label .
OPTIONAL {?r schema:comments ?comments .}
OPTIONAL {?r schema:rating ?rating .}
filter (?owner =<http://xxxx.net/resource/37654824-334f-4e57-a40c-4078cac9c579>)
{
SELECT (count(distinct ?owner) as ?allOwners)
FROM <http://xxxx.net/>
where {
?relation rdf:type <http://schema.org/Relation> .
?relation schema:owner ?owner .
?relation schema:property ?uri .
} group by ?uri
}
}
but it duplicates the result along with random count values.
How to write such a query, I know the inner query runs before the outer but how to use ?uri (subject) being used in the inner query for each record of outer result?