0

Is it possible to use aggregates in a SPARQL CONSTRUCT query? If yes, how?

I have the following (simplified) query which works:

CONSTRUCT { 
    ?s ei:number ?number .
}
FROM <http://example.org>
WHERE { 
    ?s ei:number ?number
} 

However, since ?number has multiple solutions, I would like to calculate the aggregate. I tried it like this:

CONSTRUCT { 
    ?s ei:number AVG(?number) .
}
FROM <http://example.org>
WHERE { 
    ?s ei:number ?number
} 

The SPARQL Query Validator raises the following error:

Encountered " "avg" "AVG "" at line 3, column 14.
Was expecting one of:
     ...
     ...
     ...
     ...
     ...
     ...
    "true" ...
    "false" ...
     ...
     ...
     ...
     ...
     ...
     ...
     ...
     ...
     ...
     ...
     ...
     ...
     ...
    "(" ...
     ...
    "[" ...
     ...

Hence, my question is: (How) can I use aggregates in SPARQL CONSTRUCT queries?

beta
  • 5,324
  • 15
  • 57
  • 99
  • 2
    You'll need to use a subquery in the WHERE part to use the aggregates, and the construct based on that data. E.g., does [this answer](http://stackoverflow.com/a/28427795/1281433) from [SPARQL functions in CONSTRUCT/WHERE](http://stackoverflow.com/q/28427219/1281433) work for you? – Joshua Taylor Nov 02 '15 at 13:39
  • 2
    Asked and answered on the Jena users list. – AndyS Nov 02 '15 at 14:37

0 Answers0