Trying to get three (or more count result in the same SPARQL query:
尝试获得三个(或更多计数结果在相同的SPARQL查询中:
SELECT
?cs
?bs
?ws
WHERE {
{ SELECT (COUNT(?c) AS ?cs) WHERE { ?c a :OneThing . }}
UNION
{ SELECT (COUNT(?b) AS ?bs) WHERE { ?b a :AnotherThing . } }
UNION
{ SELECT (COUNT(?w) AS ?ws) WHERE { ?w a :ThirdThing . } }
}
However, it would be much better if there were just one row with the results rather than three (and the counts on the diagonal). Tried different expressions to no avail.
但是,如果结果只有一行而不是三行(以及对角线上的计数),那会好得多。试过不同的表达无济于事。
Can this be done efficiently with SPARQL? I feel like I am missing something obvious...
这可以通过SPARQL高效完成吗?我觉得我错过了一些明显的东西......
1 个解决方案
#1
Does this do the trick?
这样做有用吗?
SELECT (COUNT(?c) AS ?cs) (COUNT(?b) AS ?bs) (COUNT(?w) AS ?ws)
WHERE {
{ ?c a :OneThing . }
UNION
{ ?b a :AnotherThing . }
UNION
{ ?w a :ThirdThing . }
}
#1
Does this do the trick?
这样做有用吗?
SELECT (COUNT(?c) AS ?cs) (COUNT(?b) AS ?bs) (COUNT(?w) AS ?ws)
WHERE {
{ ?c a :OneThing . }
UNION
{ ?b a :AnotherThing . }
UNION
{ ?w a :ThirdThing . }
}