Following this qeustion: Summer in Greece with SPARQL, since my memory runs out when executing this query, I would like to constrain the query between two regional units, but I can't group them:
SELECT * #?municipality (?bwCount1+?bwCount2 as ?bwCount)
WHERE {
{
SELECT (COUNT(?bw) as ?bwCount1) WHERE
{
?regional_unit geo:έχει_επίσημο_όνομα "ΠΕΡΙΦΕΡΕΙΑΚΗ ΕΝΟΤΗΤΑ ΗΡΑΚΛΕΙΟΥ" .
?municipality1 geo:ανήκει_σε ?regional_unit .
?municipality1 geo:έχει_γεωμετρία ?geometry .
?bw geos:hasGeometry ?bw_geo .
?bw_geo geos:asWKT ?bw_geo_wkt .
FILTER(strdf:within(?geometry, ?bw_geo_wkt)) .
?bw unt:has_concie_0 ?concie_0 .
FILTER(?concie_0 > 40)
}
}
UNION
{
SELECT (COUNT(?bw) as ?bwCount2) WHERE
{
?regional_unit geo:έχει_επίσημο_όνομα "ΠΕΡΙΦΕΡΕΙΑΚΗ ΕΝΟΤΗΤΑ ΛΕΣΒΟΥ" .
?municipality2 geo:ανήκει_σε ?regional_unit .
?municipality2 geo:έχει_γεωμετρία ?geometry .
?bw geos:hasGeometry ?bw_geo .
?bw_geo geos:asWKT ?bw_geo_wkt .
FILTER(strdf:within(?geometry, ?bw_geo_wkt)) .
?bw unt:has_concie_0 ?concie_0 .
FILTER(?concie_0 > 40)
}
}
}
#GROUP BY ?municipality
#ORDER BY DESC(?bwCount)
What am I missing?
You may again be confusing yourself with the sub-selects, and this could be causing inefficient use of memory. I see a couple of way of getting the results I believe you want (it is a bit unclear). The first is by using
UNION
:A best practice here is to not repeat triple patterns inside the
UNION
unless they are part of the disjunction computation.You could also do this with a
group by
on ?regional_unit: