← every query · class 09 · queries/q2-orders-with-several-manufacturers.rq
Q2 · Which orders contain products from more than one manufacturer?
The same answer in both regimes: this query asks only for what was written.
| ?order | ?manufacturers |
|---|---|
| order:1001 | "2"^^xsd:integer |
The query
# Q2. Which orders contain products from more than one manufacturer?
PREFIX onto: <https://data.csoares.me/onto#>
# COUNT(DISTINCT ?m): two products of the same manufacturer count once
SELECT ?order (COUNT(DISTINCT ?m) AS ?manufacturers)
WHERE {
?order a onto:Order ;
onto:containsProduct ?p .
?p onto:manufacturedBy ?m .
}
GROUP BY ?order
HAVING (COUNT(DISTINCT ?m) > 1)
ORDER BY DESC(?manufacturers)