We’re overhauling Dgraph’s docs to make them clearer and more approachable. If
you notice any issues during this transition or have suggestions, please
let us know.
AG(val(varName))
For AG
replaced with
min
: select the minimum value in the value variablevarName
max
: select the maximum valuesum
: sum all values in value variablevarName
avg
: calculate the average of values invarName
Aggregation | Schema Types |
---|---|
min / max | int , float , string , dateTime , default |
sum / avg | int , float |
A
and B
are the lists of all UIDs that match these blocks. Value
variable x
is a mapping from UIDs in B
to values. The aggregation
min(val(x))
, however, is computed for each UID in A
. That is, it has a
semantics of: for each UID in A
, take the slice of x
that corresponds to
A
’s outgoing predicateB
edges and compute the aggregation for those values.
Aggregations can themselves be assigned to value variables, making a UID to
aggregation map.
Min
Usage at root
Query Example: Get the min initial release date for any Harry Potter movie. The release date is assigned to a variable, then it’s aggregated and fetched in an empty block.json { var(func: allofterms(name@en, "Harry Potter")) { d as initial_release_date } me() { min(val(d)) } }
Usage at other levels
Query Example: Directors called Steven and the date of release of their first movie, in ascending order of first movie.Max
Usage at root
Query Example: Get the max initial release date for any Harry Potter movie. The release date is assigned to a variable, then it’s aggregated and fetched in an empty block.json { var(func: allofterms(name@en, "Harry Potter")) { d as initial_release_date } me() { max(val(d)) } }