Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

SQL AVG() Function



The SQL AVG() Function


In SQL, the AVG() function is an aggregate function used to calculate the average value of a set of values in a column. It operates on a column of numerical data and returns the average of all the values in that column.

Here's the syntax for using the AVG() function:

    SELECT AVG(column_name)
    FROM table_name;
    

Example:

Let's say we have a table called sales with a column named amount representing the sales amount for each transaction. We want to find the average sales amount:

    SELECT AVG(amount) AS average_sales_amount
    FROM sales;
    

In this example:

The AVG() function can also be combined with other clauses such as GROUP BY to calculate averages for groups of rows based on certain criteria.

Example:

Let's say we want to find the average sales amount for each product category:

    SELECT product_category, AVG(amount) AS average_sales_amount
    FROM sales
    GROUP BY product_category;
    

In this example:



Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java