ELEVATE YOUR BUSINESS WITH

Limitless customization options & Elementor compatibility let anyone create a beautiful website with Valiance.

Avg in PostgreSql

SELECT * FROM `itio_tutorial_master` WHERE `tutorial_menu`='6' AND `tutorial_submenu`='166' AND `tutorial_status`=1 LIMIT 1

Avg in PostgreSql

AVG() in PostgreSQL

The AVG() function in PostgreSQL calculates the average (mean) value of a numeric column.

Syntax

SELECT AVG(column_name) FROM table_name WHERE condition;


1. Calculating the Average of a Column

SELECT AVG(salary) FROM employees;

✅ Returns the average salary of all employees.


2. Using AVG() with a WHERE Condition

SELECT AVG(salary) FROM employees WHERE department = 'IT';

✅ Returns the average salary of employees in the IT department.


3. Using AVG() with GROUP BY

SELECT department, AVG(salary) FROM employees GROUP BY department;

✅ Returns the average salary for each department.


4. Using ROUND() to Format the Result

By default, AVG() returns a decimal value. You can round it to a specific number of decimal places:

SELECT ROUND(AVG(salary), 2) FROM employees;

✅ Returns the average salary rounded to 2 decimal places.


5. Handling NULL Values in AVG()

  • AVG() ignores NULL values in calculations.
  • If all values are NULL, it returns NULL.

Example:

SELECT AVG(bonus) FROM employees;

✅ If some employees don’t have a bonus (NULL), they are not included in the calculation.

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql