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.

round-pushpin Groups the synonyms by source word and computes several aggregates.
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
    SourceWordId

round-pushpin Counts the words of each language, largest first.
SELECT
    LanguageId,
    Count(0) as Words
FROM
    WordList:Word
GROUP BY
    LanguageId
ORDER BY
    Count(0) DESC

round-pushpin Aggregates without GROUP BY.
SELECT Count(0) as Words, Min(Id) as FirstId, Max(Id) as LastId FROM WordList:Word




SQL :: MaxString
Returns the alphabetically largest value in each group.
SQL :: Mean
Returns the arithmetic mean of the values in each group (the same as Avg).
SQL :: Median
Returns the median (middle) value in each group. For an even number of values it is the average of the two middle values.
SQL :: Min
Returns the smallest numeric value in each group. Use MinString for text.
SQL :: MinString
Returns the alphabetically smallest value in each group.
SQL :: Mode
Returns the value that occurs most often in each group. When several values are tied, the first one encountered is returned.
SQL :: Order By
Order by sorts a result set by a given set of fields or expressions.
SQL :: Select
Select statements are used to read (or query) data from the database.
SQL :: Sha1Agg
Returns a single SHA-1 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 :: Sha256Agg
Returns a single SHA-256 hash of all of the values in each group, as a lower case hex string. Useful for detecting changes to a set of documents.