Aggregated expression '%1' contains multiple columns of which one or more are outer references

Item Value
SQLCODE -861
Constant SQLE_MULTIPLE_AGGREGATE_COLUMNS
SQLSTATE 42W68
Sybase error code 13865
ODBC 2 State 37000
ODBC 3 State 42000
Parameter 1 The aggregated expression in error.

Probable cause 

A subselect within the nested query contains an aggregate function whose parameters include an outer reference. In such cases, the outer reference must be the only column referenced in the expression.