Skip to main content

Analytical Queries - Aggregate Variables

Any variables bound in the where clauses, can be used in conjunction with aggregate functions. For example, the below query takes the sum of ?nums.

"select": "(sum ?nums)",
"where": [["$fdb8", ["person/handle", "zsmith"], "person/favNums", "?nums"]]

The full list of available variables is below:

avgReturns the average of the values.
countReturns a count of the values.
count-distinctReturns a count of the distinct values.
distinctReturns all of the distinct values.
maxReturns the largest value.
medianReturns the median of the values.
minReturns the smallest value.
randReturns a random value from the specified values.
sampleGiven a sample size and a set of values, returns an appropriately sized sample, i.e. (sample 2 ?age) returns two ages from values bound to the variable, ?age.
stddevReturns the standard deviation of the values.
sumReturns the sum of the values.
varianceReturns the variance of the values.

Modify the Query

Modify the above query, to take a random number from ?nums.