LQL statements typically use expressions to compute one or more derived attributes.
Each aggregation operation can declare an arbitrary set of named expressions, sometimes referred to as derived attributes, using SELECT AS syntax. These expressions represent aggregate analytic functions that are computed for each aggregated record in the statement result.
RETURN foo AS SELECT AVG(Price) AS "Average Price"The space would have to be removed:
RETURN foo AS SELECT AVG(Price) AS "AveragePrice"
Function | Description |
---|---|
AVG | Computes the arithmetic mean value for a field. |
COUNT | Counts the number of records with valid non-null values in a field for each GROUP BY result. |
COUNTDISTINCT | Counts the number of unique, valid non-null values in a field for each GROUP BY result. |
MAX | Finds the maximum value for a field. |
MIN | Finds the minimum value for a field. |
MEDIAN | Finds the median value for a field. |
STDDEV | Computes the standard deviation for a field. |
ARB | Selects an arbitrary but consistent value from the set of values in a field. |
SUM | Computes the sum of field values. |
VARIANCE | Computes the variance (that is, the square of the standard deviation) for a field. |
LQL supports the following numeric functions:
Function | Description |
---|---|
addition | The addition operator (+). |
subtraction | The subtraction operator (-). |
multiplication | The multiplication operator (*). |
division | The division operator (/). |
ABS | Returns the absolute value of
n.
If n is 0 or a positive integer, returns n. Otherwise, n is multiplied by -1. |
CEIL | Returns the smallest integer value not less than n. |
EXP | Exponentiation, where the base is
e.
Returns the value of e (the base of natural logarithms) raised to the power of n. |
FLOOR | Returns the largest integer value not greater than n. |
LN | Natural logarithm. Computes the logarithm of its single argument, the base of which is e. |
LOG | Logarithm. log(n, m) takes two arguments, where n is the base, and m is the value you are taking the logarithm of. |
MOD | Modulo. Returns the remainder of
n divided by
m.
LQL uses the fmod floating point remainder, as defined in the C/POSIX standard. |
ROUND | Returns a number rounded to the specified
decimal place.
The unary version drops the decimal (non-integral) portion of the input. The binary version allows you to set the number of spaces at
which the number is rounded:
|
SIGN | Returns the sign of the argument as -1, 0, or 1, depending on whether n is negative, zero, or positive. |
SQRT | Returns the nonnegative square root of n. |
TRUNC | Returns the number
n, truncated to
m decimals.
If m is 0, the result has no decimal point or fractional part. The unary version drops the decimal (non-integral) portion of the input, while the binary version allows you to set the number of spaces at which the number is truncated. |
SIN | The sine of n, where the angle of n is in radians. |
COS | The cosine of n, where the angle of n is in radians. |
TAN | The tangent of n, where the angle of n is in radians. |
POWER | Returns the value of n raised to the power of m. |
TO_DURATION | Casts an integer into a number of
milliseconds so that it can be used as a duration.
When TO_DURATION is given a value of type double, it removes the decimal portion and converts the integer portion to a duration. |
The COALESCE expression allows for user-specified null-handling.
AVG(COALESCE(price, 0))COALESCE can also be used without aggregation, for example:
SELECT COALESCE(price, 0) AS price_or_zero WHERE