...
1. If a set function (AVG, COUNT, MAX, MIN, STDDEV, SUM, VARIANCE) occurs in a SELECT statement, non-group columns are not allowed in the selected columns (select_column).
2. Quantity functions, e.g. AVG (SUM...), must not be nested.
3. A corresponding subquery S contained in the WHERE clause of the QUERY specification Q must not contain quantity functions for columns of tables specified in the FROM clause of the QUERY specification Q.
Correct the SQL statement.
Try to achieve the desired effect without nesting the quantity functions by using several QUERY statements, each containing a quantity function.
Within a QUERY statement, the effect can be achieved by specifying a QUERY expression in the FROM clause.