Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using SUM instead of COUNT.
Using TOTAL or NUMBER which are not valid SQL functions.
✗ Incorrect
The COUNT function counts the number of rows. Using COUNT(*) counts all rows in the table.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using COUNT(*) which counts all rows regardless of nulls.
Using COUNT(NULL) which always returns zero.
✗ Incorrect
COUNT(column) counts only non-null values in that column. Here, COUNT(salary) counts all employees with a salary value.
3fill in blank
hardFix 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'
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.
✗ Incorrect
COUNT(DISTINCT column) counts unique non-null values in that column. DISTINCT is the correct keyword.
4fill in blank
hardFill 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'
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.
✗ Incorrect
COUNT(*) counts all rows matching the condition. The condition salary > 50000 filters employees with salary above 50000.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of < which counts salaries greater than 70000.
Not using DISTINCT which counts duplicates.
✗ Incorrect
COUNT(DISTINCT job_title) counts unique job titles. The condition salary < 70000 filters employees with salary less than 70000.