Grouping
WHERE filters rows before grouping; HAVING filters groups after. Use WHERE for row-level conditions and HAVING for conditions on aggregate
results. The planner may push eligible predicates earlier in the query.
Grouping by several expressions produces one row per distinct combination:
Aggregate without grouping
OmittingGROUP BY aggregates the whole table into one row, which is the usual way to
ask how big something is:
count(*) counts rows; count(col) counts non-null values, which is how you
measure how populated a computed column
is before deciding to refresh it again.
The function set
Registered in DataFusion 54. Names below are what is actually available. Generalapprox_distinct answers “roughly how many distinct values” for a fraction of
what count(DISTINCT ...) costs, which can help with high-cardinality columns. Measure the accuracy and runtime
for your workload.
DISTINCT works inside an aggregate: count(DISTINCT category). FILTER
narrows one aggregate without narrowing the others: