Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Select Avg in SQL

Select Avg in SQL

? SELECT AVG() in SQL

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


? Syntax:

SELECT AVG(column_name) FROM table_name WHERE condition;
  • column_name: The numeric column for which you want to find the average.

  • WHERE: Optional condition to filter rows.


? Examples:

Average salary from employees table:

SELECT AVG(salary) AS average_salary FROM employees;

Average salary for employees in 'Sales' department:

SELECT AVG(salary) AS avg_sales_salaryFROM employeesWHERE department = 'Sales';

Average price of products with price > 100:

SELECT AVG(price) AS avg_priceFROM productsWHERE price > 100;

? Notes:

  • AVG() ignores NULL values.

  • Often used with GROUP BY to get averages per group:

SELECT department, AVG(salary) AS avg_salaryFROM employeesGROUP BY department;

Want examples using AVG() with grouping or joins?

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