Easy
Count length of names
Count the length of each unique first name present in the students
table. Sort the results by length of name in descending order, so the longest names appear first.
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
+-------------+--------+
| first_name | length |
+-------------+--------+
| Jacqueline | 10 |
| Caroline | 8 |
| ... | ... |
+-------------+--------+
Use ORDER BY col_name DESC
to sort a given column col_name
in descending order.
Use the keyword LENGTH()
is used to get the length of an item.
SELECT
first_name,
LENGTH(first_name)
FROM students
ORDER BY 2 DESC