Easy

Count rows which meet a condition I

Count the number of students in the students table whose first name contains the letter 'u' (upper-case or lower-case).

SCHEMA

students

+------------+------------+-----------+-----+------------+
| student_id | first_name | last_name | age | class_code |
+------------+------------+-----------+-----+------------+
| 1          | Mike       | Chaplin   | 12  | 7A         |
| 2          | Emily      | Jackson   | 12  | 7A         |
| 3          | Robert     | Jackson   | 12  | 7A         |
| ...        | ...        | ...       | ... | ...        |
+------------+------------+-----------+-----+------------+
EXPECTED OUTPUT
+------------------------------+
| num_first_names_containing_u |
+------------------------------+
| 60                           |
+------------------------------+

Use the WHERE keyword to filter the students table.

Use the LOWER() keyword to convert all first names to lowercase, and then use a regex pattern like '%u%' to match first names which contain a 'u'.

SELECT COUNT(*) AS num_first_names_containing_u FROM students WHERE LOWER(first_name) LIKE '%u%'

  • This field is required.