How is the average function in SQL used?
The SQL AVG function is used to calculate the average of a column. In SQL, you can use the AVG() function to compute the average of a column.
For example, if there is a table called “sales” with a column named “amount” that stores the sales amount, you can calculate the average of the “amount” column using the following SQL query:
SELECT AVG(amount) AS avg_amount
FROM sales;
The above query will calculate the average of the “amount” column and rename it as “avg_amount”. You can also add a WHERE clause to the query to filter specific data for the average calculation as needed.