How to Find the Average of a Numeric Column in SQL

To find the average of a numeric column in your database using SQL, use the AVG() function. This function takes a single argument, which is the column you want to find the average of. For example, if you wanted to find the average of the age column of your database, you would use the following query:

SELECT AVG(age) FROM table_name;

Examples

Let's look at a few examples of how this function can be used. Suppose you have a table called users with the following data:

users
nameage
John25
Jane30
John25
Bob20


If you wanted to find the average age of the users in this table, you would use the following query:

SELECT AVG(age) FROM users;

This query would return the result 25, since the average age of the users in the table is 25.

Additional Info

The AVG() function is supported by most major databases, including MySQL, PostgreSQL, and SQL Server. However, the syntax may vary slightly depending on the database you are using. For more information, check out the documentation for your particular database.

Want to build your own LLM Apps with AirOps👇👇