Skip to content
Joshua Weinberg edited this page Nov 24, 2021 · 2 revisions

HAVING

A WHERE clause for GROUP BY

The HAVING clause is used to filter the results of a GROUP BY operation. It is functionally equivalent to the WHERE operation and in SQLToy is implemented the same way.

const HAVING = (table, pred) => {
  return {
    name: table.name,
    rows: table.rows.filter(pred)
  }
}

The resulting table only includes rows which satisfy the predicate. Since it is run after the GROUP BY and Aggregate Functions the predicate can reference columns created by them like AVG() or MAX().

For a discussion of filtering using a predicate refer to WHERE.


Next section: SELECT

Clone this wiki locally