There are several rules to consider when using the compute clause.
SAP ASE does not allow the distinct keyword with the row aggregates.
The columns in a compute clause must also be in the select list.
You cannot use select into in the same statement as a compute clause because statements that include compute do not generate normal rows.
You cannot use a compute clause in a select statement within an insert statement, for the same reason: statements that include compute do not generate normal rows.
If you use compute with the by keyword, you must also use an order by clause. The columns listed after by must be identical to, or a subset of, those listed after order by, and must be in the same left-to-right order, start with the same expression, and cannot skip any expressions.
For example, suppose the order by clause is:
order by a, b, c
The compute clause can be any or all of these:
compute row_aggregate (column_name) by a, b, c
compute row_aggregate (column_name) by a, b
compute row_aggregate (column_name) by a
The compute clause cannot be any of these:
compute row_aggregate (column_name) by b, c
compute row_aggregate (column_name) by a, c
compute row_aggregate (column_name) by c
You must use a column name or an expression in the order by clause; you cannot sort by a column heading.
You can use the compute keyword without by to generate grand totals, grand counts, and so on. order by is optional if you use the compute keyword without by.