0
0
SQLquery~5 mins

AVG function in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the AVG function do in SQL?
The AVG function calculates the average (mean) value of a numeric column in a table.
Click to reveal answer
beginner
How do you use the AVG function to find the average salary from an Employees table?
Use: <br>SELECT AVG(salary) FROM Employees;<br>This returns the average salary of all employees.
Click to reveal answer
beginner
Can the AVG function be used with non-numeric columns?
No, AVG only works with numeric columns like integers or decimals. Using it on text or dates will cause an error.
Click to reveal answer
intermediate
What happens if the AVG function is used on a column with NULL values?
NULL values are ignored by AVG. It calculates the average only from the non-NULL values.
Click to reveal answer
intermediate
How can you find the average salary per department using AVG?
Use GROUP BY with AVG:<br>SELECT department, AVG(salary) FROM Employees GROUP BY department;<br>This shows average salary for each department.
Click to reveal answer
What does the SQL AVG function calculate?
AThe total sum of a numeric column
BThe average value of a numeric column
CThe maximum value in a column
DThe number of rows in a table
Which SQL query correctly finds the average price from a Products table?
ASELECT AVG(price) FROM Products;
BSELECT SUM(price) FROM Products;
CSELECT COUNT(price) FROM Products;
DSELECT MAX(price) FROM Products;
How does AVG handle NULL values in a column?
AIt counts NULL as one
BIt treats NULL as zero
CIt ignores NULL values and averages only non-NULL values
DIt returns NULL if any NULL exists
Can AVG be used on a text column?
ANo, AVG only works with numeric columns
BYes, AVG converts text to numbers automatically
CYes, AVG counts the number of text entries
DNo, AVG only works with date columns
How do you find the average salary per department?
ASELECT department, SUM(salary) FROM Employees;
BSELECT AVG(salary) FROM Employees;
CSELECT department FROM Employees WHERE AVG(salary);
DSELECT department, AVG(salary) FROM Employees GROUP BY department;
Explain how the AVG function works in SQL and how it treats NULL values.
Think about how average is calculated in math and what happens if some values are missing.
You got /3 concepts.
    Describe how to use the AVG function with GROUP BY to find averages per category.
    Grouping data helps calculate averages for each group separately.
    You got /3 concepts.