0
0
MySQLquery~10 mins

COUNT 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 count all rows in the employees table.

MySQL
SELECT [1](*) FROM employees;
Drag options to blanks, or click blank then click option'
ATOTAL
BSUM
CCOUNT
DNUMBER
Attempts:
3 left
💡 Hint
Common Mistakes
Using SUM instead of COUNT.
Using TOTAL or NUMBER which are not valid SQL functions.
2fill in blank
medium

Complete the code to count only the non-null values in the salary column.

MySQL
SELECT COUNT([1]) FROM employees;
Drag options to blanks, or click blank then click option'
Asalary
BDISTINCT salary
CNULL
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using COUNT(*) which counts all rows regardless of nulls.
Using COUNT(NULL) which always returns zero.
3fill in blank
hard

Fix the error in the code to count distinct departments.

MySQL
SELECT COUNT([1] department) FROM employees;
Drag options to blanks, or click blank then click option'
ASINGLE
BALL
CUNIQUE
DDISTINCT
Attempts:
3 left
💡 Hint
Common Mistakes
Using ALL which counts all values including duplicates.
Using UNIQUE or SINGLE which are not valid SQL keywords here.
4fill in blank
hard

Fill both blanks to count employees with salary greater than 50000.

MySQL
SELECT COUNT([1]) FROM employees WHERE salary [2] 50000;
Drag options to blanks, or click blank then click option'
A*
Bsalary
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using COUNT(salary) which counts only non-null salaries but is less clear here.
Using < instead of > which counts salaries less than 50000.
5fill in blank
hard

Fill all three blanks to count distinct job titles with salary less than 70000.

MySQL
SELECT COUNT([1] job_title) FROM employees WHERE salary [2] [3];
Drag options to blanks, or click blank then click option'
ADISTINCT
B<
C70000
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of < which counts salaries greater than 70000.
Not using DISTINCT which counts duplicates.