Skip to main content
FiQueLa supports SQL-style grouping and aggregation. Use groupBy() to collapse rows into groups, aggregate functions to compute group-level summaries, and having() to filter the aggregated results.

WHERE vs HAVING

The key distinction:
  • WHERE — filters rows before grouping. Only rows that pass the filter are included in the groups.
  • HAVING — filters groups after aggregation. Conditions can reference aggregate aliases.

groupBy()

Group rows by one or more fields. Dot notation is supported for nested fields:
FiQueLa 3.0groupBy() accepts any SQL expression, including function calls and infix arithmetic. The expression is evaluated for each row and the result is used as the grouping key.
The same applies to aggregate helpers — sum(), avg(), min(), max(), and groupConcat() accept full expressions:
DISTINCT and GROUP BY cannot be used together. Attempting to combine them throws a QueryLogicException.

Aggregate functions

All aggregate methods accept an optional bool $distinct parameter (except avg()). groupConcat() also accepts a separator string.

Examples

DISTINCT in aggregates

Pass true as the last argument to count, sum, min, max, or groupConcat only unique values:

Real-world example

This example comes from the XML example — grouping customers by age and computing average spending:
Equivalent FQL: