0
0
MySQLquery~10 mins

AVG function in MySQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to calculate the average salary from the employees table.

MySQL
SELECT [1](salary) FROM employees;
Drag options to blanks, or click blank then click option'
AAVG
BMAX
CCOUNT
DSUM
Attempts:
3 left
💡 Hint
Common Mistakes
Using SUM instead of AVG will give the total, not the average.
Using COUNT will count rows, not calculate average.
2fill in blank
medium

Complete the code to find the average price from the products table where category is 'Books'.

MySQL
SELECT AVG(price) FROM products WHERE category = [1];
Drag options to blanks, or click blank then click option'
A"Books"
BBooks
C'Books'
DBooks'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around string values causes syntax errors.
Using double quotes may not work depending on SQL mode.
3fill in blank
hard

Fix the error in the code to correctly calculate the average age from the users table.

MySQL
SELECT AVG[1]age FROM users;
Drag options to blanks, or click blank then click option'
A{age}
Bage
C[age]
D(age)
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting parentheses causes syntax errors.
Using brackets or braces is invalid in SQL function calls.
4fill in blank
hard

Fill both blanks to calculate the average score for students with grade greater than 80.

MySQL
SELECT [1](score) FROM students WHERE grade [2] 80;
Drag options to blanks, or click blank then click option'
AAVG
B>
C<
DSUM
Attempts:
3 left
💡 Hint
Common Mistakes
Using SUM instead of AVG will sum scores, not average.
Using < instead of > will select wrong rows.
5fill in blank
hard

Fill all three blanks to calculate the average price for products with stock less than 50 and category 'Electronics'.

MySQL
SELECT [1](price) FROM products WHERE stock [2] 50 AND category = [3];
Drag options to blanks, or click blank then click option'
AAVG
B<
C'Electronics'
DSUM
Attempts:
3 left
💡 Hint
Common Mistakes
Using SUM instead of AVG.
Forgetting quotes around 'Electronics'.
Using > instead of < for stock condition.