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:
Function | Description |
---|---|
avg | Returns the average of the values. |
count | Returns a count of the values. |
count-distinct | Returns a count of the distinct values. |
distinct | Returns all of the distinct values. |
max | Returns the largest value. |
median | Returns the median of the values. |
min | Returns the smallest value. |
rand | Returns a random value from the specified values. |
sample | Given 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 . |
stddev | Returns the standard deviation of the values. |
sum | Returns the sum of the values. |
variance | Returns the variance of the values. |
Modify the Query
Modify the above query, to take a random number from ?nums.