Numeric Functions
Mathematical and numeric functions for calculations, rounding, and trigonometry in SDBQL.
Numeric Operations
Basic Math
Powers & Roots
Logarithms
Trigonometry
Aggregation Functions
Statistical Functions
Practical Examples
-- Calculate user order statistics
FOR u IN users
LET amounts = (FOR o IN orders FILTER o.user == u._key RETURN o.amount)
RETURN {
user: u.name,
total: SUM(amounts),
avg: ROUND(AVG(amounts), 2),
count: COUNT(amounts),
median: MEDIAN(amounts),
stddev: ROUND(STDDEV(amounts), 2)
}
-- Calculate distance between two points
LET x1 = 3, y1 = 4, x2 = 0, y2 = 0
RETURN SQRT(POW(x2 - x1, 2) + POW(y2 - y1, 2)) -- 5
-- Generate random sample
FOR i IN RANGE(1, 10)
RETURN FLOOR(RANDOM() * 100) -- Random integers 0-99
-- Calculate compound interest
LET principal = 1000, rate = 0.05, years = 10
RETURN ROUND(principal * POW(1 + rate, years), 2) -- 1628.89