Content
AVG calculates the average value of a numeric column. Essential for statistical analysis and reporting.
Basic AVG Syntax
SELECT AVG(column) FROM table;
Calculate Average
SELECT AVG(price) as avg_price FROM products;
AVG with Condition
SELECT AVG(salary) FROM employees WHERE department = 'Engineering';
AVG with GROUP BY
SELECT department, AVG(salary) as avg_salary
FROM employees
GROUP BY department;
AVG with ROUND
SELECT ROUND(AVG(rating), 2) as avg_rating FROM reviews;
AVG vs SUM/COUNT
-- These are equivalent
SELECT AVG(price) FROM products;
SELECT SUM(price) / COUNT(price) FROM products;
Generate AVG Queries
Ask about averages and AI2sql handles the calculation.


