Find Employees Whose Names Start With A and Have at Least 5 Characters
Company: Cognizant
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: easy
Interview Round: Other
Find employees whose `name` starts with 'A' and has at least 5 characters. Return `id`, `name`, and the name length as `name_length`, ordered by `name` ascending, then `id` ascending.
```hint Two separate tests
The first letter and the length are two independent conditions. Before you trust the filter, check how your database's pattern match treats upper and lower case.
```
### Input Table(s)
`employees`
| Column | Type | Meaning |
|---|---|---|
| id | INT | Employee id |
| name | VARCHAR(100) | Employee name, NOT NULL |
| department | VARCHAR(50) | Department name, may be NULL |
| salary | DECIMAL(10,2) | Salary, may be NULL |
Primary key: `id`.
### Output Contract
Columns in this order: `id`, `name`, `name_length` (an integer, the number of characters in `name`). Return one row per qualifying employee. Order by `name` ascending, compared case-insensitively, then by `id` ascending. `id` is unique, so the order is unique.
### Example
Input `employees`:
| id | name | department | salary |
|---|---|---|---|
| 1 | Alice | Engineering | 85000 |
| 2 | Bob | Marketing | 72000 |
| 3 | Amanda | Engineering | 90000 |
| 4 | Alex | Sales | 68000 |
| 5 | Andrew | Marketing | 75000 |
| 6 | Anna | Sales | 60000 |
| 7 | Benjamin | Engineering | 95000 |
Expected output:
| id | name | name_length |
|---|---|---|
| 1 | Alice | 5 |
| 3 | Amanda | 6 |
| 5 | Andrew | 6 |
The names starting with 'A' are Alice (5), Amanda (6), Alex (4), Andrew (6) and Anna (4). Only Alice, Amanda and Andrew have 5 or more characters. Alex and Anna have 4 characters and are excluded, and Bob and Benjamin start with 'B'.
### Constraints and Clarifications
- `employees` has at most 10,000 rows.
- `name` is never NULL and consists of English letters only (no spaces or special characters), with length 1 to 100.
- The first-letter test is case-insensitive, so a name stored as 'alice' also qualifies.
- Two names that are equal when compared case-insensitively, or exactly equal, are ordered by `id`.
- `department` and `salary` play no part in the filter or the output.
Overview: Write a SQL query that returns employees whose names begin with the letter A and have at least five characters, along with the length of each name. It tests pattern matching with LIKE or ILIKE, string length functions, case handling and deterministic ordering.