Informix Error -544: Cannot have aggregates within aggregates.
Cause and resolution
Cannot have aggregates within aggregates.
The statement contains a call on an aggregate function within the parameter list for another aggregate function, such as SUM(MAX(column)). This action is not supported because all aggregates are calculated over the same groups of rows. If you did not intend an expression of this sort, look for missing or misplaced parentheses. If you did intend it, rethink the query. For example, you might select the MAX values into a temporary table and then take their SUM.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-544 fires when one aggregate function's argument is itself a call to another aggregate function
(SUM(MAX(column)) and similar) — since all aggregates in a statement are computed over the same
groups of rows, nesting them isn't a meaningful operation the server can evaluate in one pass.
- Genuinely nested aggregate syntax, per the official guidance's example
SUM(MAX(column))— the direct, only cause. - Missing or misplaced parentheses, per the official guidance, producing an expression that parses as nested aggregates when something else was intended.
- A misunderstanding of what the query is trying to compute — wanting an aggregate-of- aggregates (e.g. "the sum of each group's maximum") without realizing that requires two separate query steps.
Solutions / Resolution
- Check for missing or misplaced parentheses first, per the official guidance, in case the nesting wasn't actually intended.
- If an aggregate-of-aggregates is genuinely needed, per the official guidance, select the
inner aggregate's values into a temporary table, then take the outer aggregate over that:
SELECT customer_id, MAX(order_total) AS max_total FROM orders GROUP BY customer_id INTO TEMP customer_maxes; SELECT SUM(max_total) FROM customer_maxes;
Examples
The disallowed nesting
SELECT SUM(MAX(order_total)) FROM orders GROUP BY customer_id;
-- -544: MAX() nested inside SUM()
The two-step rewrite
SELECT customer_id, MAX(order_total) AS max_total
FROM orders GROUP BY customer_id
INTO TEMP customer_maxes;
SELECT SUM(max_total) FROM customer_maxes;
Diagnostic Checks
- Re-read the expression's parenthesization to confirm nesting was actually intended, not a punctuation slip.
- Identify which two aggregates are involved and whether a temp-table staging step (as above) achieves the intended two-level aggregation.
Related Errors / Related Topics
No closely related error codes are cross-referenced for -544 in this set yet.
Split a genuine aggregate-of-aggregates into two query steps via a temp table — one pass can't compute nested aggregates directly.