- From: Fred Zemke <fred.zemke@oracle.com>
- Date: Thu, 12 Jan 2006 13:43:33 -0800
- To: public-rdf-dawg-comments@w3.org
There is no ability to perform aggregates, ie, computations on a
set of results. Example: find authors who have written 2 or more books.
Solution: SELECT ?author WHERE { ?author v:wrote ?book1 .
?author v:wrote ?book2 . FILTER (?book1 != ?book2) }
Now try to find authors who have written 50 or more books.
This will require 50 book variables and 50*49/2 filter predicates.
It would be easier if there were a way to count the number of books
that an author has and then filter on the count. Other commonly used
aggregates are sum, average, maximum, minimum. I don't know of any
workaround at all for computing sum or average in SPARQL. There is
a workaround for maximum and minimum, though it is messy.
Example: find the vendor with the lowest price for a widget.
SELECT ?vendor
WHERE { ?vendor v:sells ?product .
?product a w:idget .
?product v:price ?price .
?vendor2 v:sells ?product2 .
?product2 a w:idget .
?product2 v:price ?price2 .
FILTER (?price2 > ?price) }
Fred Zemke
Received on Thursday, 12 January 2006 21:43:47 UTC