SQL AVG is an aggregate function that calculates the average value of a specific column in a table.
The syntax for using the AVG function in SQL is:
SELECT AVG(column_name) FROM table_name;
For example, suppose you have a table named bookshop with a price column and you need to answer what is the average price of the books. The following query would do it for you:
SELECT AVG(price) FROM bookshop;
But if you need to know the average price only for the Fiction books, you could use a WHERE clause to calculate. Here’s how the statement would look like:
SELECT AVG(price) FROM bookshop WHERE genre = 'Fiction';
In these examples, the AVG function calculates the average value of a specific column.
SQL AVG in Coginiti
Coginiti allows you to apply the aggregation functionality to any column by dragging and dropping the values you want to find the average.
Here’s an example of how you can sum rows in Coginiti Grid:
- Open the Grid View
- Click “Columns’”
- Drag and drop the values you want to aggregate.
Note that when you drop a column to “Values,” it will come with the last function used. Click on it to change and scroll to find the aggregate function you want.