Aggregations
Aggregators only aggregate vertically - the values of a column.
SQL evaluates the aggregations before the
LIMITclause.
COUNT
COUNTSELECT COUNT (*) AS account_count
FROM accountsSELECT COUNT(primary_poc) AS account_primary_poc_count
FROM accountsSUM
SUMUnlike COUNT, you can only use SUM on numeric columns. However, SUM will ignore NULL values.
MIN, MAX & AVG
MIN, MAX & AVGGROUP BY
GROUP BYused to aggregate data within subsets of the data.
Any column in the
SELECTstatement that is not within an aggregator must be in theGROUP BYclause.You can GROUP BY multiple columns at once, The order of column names in your GROUP BY clause doesn’t matter—the results will be the same regardless.
DISTINCT
DISTINCTusing DISTINCT, particularly in aggregations, can slow your queries down quite a bit.
HAVING
DATE Functions
FunctionsCASE Statements
The CASE statement always goes in the SELECT clause.
CASE must include the following components: WHEN, THEN, and END. ELSE is an optional component to catch cases that didn’t meet any of the other previous CASE conditions.
Last updated
Was this helpful?