Group By
GROUP BY collapses the selected documents into one row for each distinct combination of the grouped fields or expressions. Fields that are not grouped can only be used inside Aggregate Functions.
When a query uses aggregate functions without GROUP BY, all of the selected documents form a single group. HAVING is not supported.
SELECT
SourceWordId,
Min(TargetWordId) as Min,
Max(TargetWordId) as Max,
Sum(TargetWordId) as Sum,
Avg(TargetWordId) as Avg,
Count(TargetWordId) as Count
FROM
WordList:Synonym
GROUP BY
SourceWordIdSELECT
LanguageId,
Count(0) as Words
FROM
WordList:Word
GROUP BY
LanguageId
ORDER BY
Count(0) DESCSELECT Count(0) as Words, Min(Id) as FirstId, Max(Id) as LastId FROM WordList:WordSQL :: Sha512Agg
Returns a single SHA-512 hash of all of the values in each group, as a lower case hex string. Useful for detecting changes to a set of documents.
SQL :: ShowAggregateFunctions
Lists the built-in aggregate functions with their parameters and descriptions.
SQL :: Sum
Returns the total of the values in each group.
SQL :: Syntax
Basic KBSQL syntax and some examples.
SQL :: Variance
Returns the population variance of the values in each group: how far the values are spread from their mean.