6.2.5 #:group and #:having clauses
SQL provides a mechanism for grouping and filtering the
results of queries that involve aggregate functions. The semantics are
confusing, unintuitive, and outside the scope of this document. Snooze
provides access to these features (for hardier programmers) via the
#:group and #:having clauses:
The #:group clause is a list of #:what items by which results should be grouped. For example:
; (listof (list employer natural-number)) |
; The number of employees working for each employer. |
(find-all |
(sql (select #:what (employer (count employee.id)) |
#:from (inner employer |
employee |
; ...) |
#:group (employer)))) |
The #:having clause is like the #:where clause but eliminates groups from the query results.