Informix Error -8104: Group aggregates can only be used in an AFTER GROUP OF clause.
Cause and resolution
Group aggregates can only be used in an AFTER GROUP OF clause.
Aggregate values over a group are accumulated while the rows of the group are being processed, so they are not available until the end of the group is seen. Therefore, the report cannot refer to them except in an AFTER GROUP OF clause.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-8104 fires when a group aggregate is referenced outside an AFTER GROUP OF clause — per the
official guidance, aggregate values over a group accumulate while the group's rows are
processed, and aren't available until the group ends.
- A group aggregate referenced outside an
AFTER GROUP OFclause, per the official guidance — the direct, only cause.
Solutions / Resolution
- Move the aggregate reference into an
AFTER GROUP OFclause, per the official guidance, since that's the only point where the group's aggregate value is complete.
Examples
An aggregate referenced too early
BEFORE GROUP OF customer_id
PRINT SUM(order_total)
-- -8104: the group's rows haven't been processed yet
Corrected
AFTER GROUP OF customer_id
PRINT SUM(order_total)
Diagnostic Checks
- Check every group-aggregate reference, and confirm it's inside the matching
AFTER GROUP OFclause.
Related Errors / Related Topics
- -8105 — "Aggregates may not be used within another aggregate. Nor may aggregates be used within the WHERE clause of another aggregate." A related aggregate-usage restriction, about nesting rather than clause placement.
A group aggregate was referenced outside its AFTER GROUP OF clause — move it there.