Saturday , March 2 2024

AVG Function In PostgreSQL

In today’s article, we will discuss the AVG Function, which helps us calculate the average value of a set in PostgreSQL.

The syntax of the AVG() function is as follows:

For example, if we want to find out the average of item sales prices in our depo table, we can use the following sentence.

First, let’s look at how many items are in the table and their prices.

We can access the desired information with the following command.

We can average item sales with the help of the following command.

The purpose of the “::numeric” expression is to see the colon as a complete character due to the $ character, and it gives an error when run without this command.

We convert it to numeric data type to avoid errors and to return a healthy result.

Loading

About Faruk Erdem

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories