In IBM DB2, the AVG function is used to calculate the average value of a set of values. Here's the syntax for the AVG function:
AVG(expression)
- expression: The column or expression for which you want to calculate the average.
Here's an example of how to use the AVG function in DB2:
Suppose you have a table named sales with a column amount that stores the sales amount for each transaction. You can use the AVG function to calculate the average sales amount:
SELECT AVG(amount) AS average_sales
FROM sales;
This query will calculate the average sales amount from the amount column in the sales table and alias the result as average_sales.
For example, if your sales table contains the following data:
| amount |
|--------|
| 100 |
| 200 |
| 300 |
| 400 |
| 500 |
The result of the query would be:
average_sales
-------------
300
This is because the average of 100, 200, 300, 400, and 500 is 300.
No comments:
Post a Comment