Previous | Home | Next |
Used to generate summary rows using aggregate function in the query results. COMPUTE BY clause can be used to calculate summary values of the result set on a group of data.The main difference between GROUP BY and COMPUTE BY Clause is,
GROUP BY Clause is used to generate a group summary report and does not produce individual table rows in the result set whereas COMPUTE BY Clause generate the summary report with individual data rows from the table.
SELECT column_name FROM table_name ORDER BY column_name COMPUTE aggregate_function (column_name) BY column_name 1...column_name n
Example:
SELECT type, advance FROM titles ORDER BY type COMPUTE AVG (advance) BY type
output
Some points regarding the use of the COMPUTE and COMPUTE BY
- The DISTINCT keyword cannot be used with the aggregate function
- All columns referred to in the COMPUTE clause must appear in the select column list
- The ORDER BY Clause must be used whenever the COMPUTE BY Clause is used
- The ORDER BY Clause can be eliminate only when the COMPUTE BY Clause is used
- The column listed in the COMPUTE BY Clause must match the columns used in the ORDER BY Clause
- More than one COMPUTE clause can be used in the SELECT statement to produce a result with subtotals and grand total
- The different aggregate function can be used on more than one column with the COMPUTE BY Clause
- More than one column or expression can be specified after the COMPUTE BY clause. The order of columns or expression used in the COMPUTE BY clause must match the order of columns or expression specified in the ORDER BY Clause.
Previous | Home | Next |