W3C home > Mailing lists > Public > public-rdf-dawg@w3.org > October to December 2011

Aggregates in ORDER BY

From: Andy Seaborne <andy.seaborne@epimorphics.com>
Date: Mon, 21 Nov 2011 14:50:08 +0000
Message-ID: <4ECA6520.70104@epimorphics.com>
To: SPARQL Working Group <public-rdf-dawg@w3.org>
The current spec doesn't include the case of an aggregate expression in 
an ORDER BY - it's just an oversight in the translation algorithm.

18.2.4.1 Grouping and Aggregation

"""
For each expression E in SELECT and each HAVING(E) in Q
"""

should be:
"""
For each expression E in SELECT, each HAVING(E) and ORDER BY in Q
"""


SELECT ?x
{ ?x :p ?v }
GROUP BY ?x
HAVING (sum(?v) > 5)
ORDER BY sum(?v)

SELECT ?x
{ ?x :p ?v }
GROUP BY ?x
HAVING (sum(?v) > 5)
ORDER BY count(*)

It allows ORDERing without needing to project a variable of the 
aggregate expression.

The processing order is
   group/agg -> having -> select expressions -> order by

so, like mention in HAVING, a mention in ORDER BY should be allowed. 
(It sort of is by LC1 in the grammar because the grammar wasn't clear - 
noted and needs fixing).

	Andy
Received on Monday, 21 November 2011 14:50:41 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 16:15:47 GMT