0
0
MySQLquery~5 mins

AVG function in MySQL - 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 price from a products table?
Use: SELECT AVG(price) FROM products; This returns the average of all values in the price column.
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 columns 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 non-NULL values.
Click to reveal answer
intermediate
How can you find the average salary per department using AVG?
Use GROUP BY: SELECT department, AVG(salary) FROM employees GROUP BY department; This shows average salary for each department.
Click to reveal answer
What does the SQL AVG function return?
AThe average value of a numeric column
BThe total sum of a numeric column
CThe highest value in a column
DThe number of rows in a table
Which SQL query correctly finds the average age from a table named users?
ASELECT AVG(age) FROM users;
BSELECT SUM(age) FROM users;
CSELECT COUNT(age) FROM users;
DSELECT MAX(age) FROM users;
How does AVG handle NULL values in a column?
AIt causes an error
BIt treats NULL as zero
CIt ignores NULL values
DIt counts NULL as one
Can AVG be used on a text column?
AYes, but only if text is numeric strings
BNo, AVG only works on numeric columns
CYes, AVG works on any column
DOnly if text is converted first
Which SQL clause is used with AVG to get averages per group?
AHAVING
BORDER BY
CWHERE
DGROUP BY
Explain how the AVG function works and how it treats NULL values.
Think about how you find an average in real life and what happens if some data is missing.
You got /3 concepts.
    Describe how to use AVG with GROUP BY to find averages per category.
    Imagine you want average scores per class in a school.
    You got /3 concepts.