AnalystPath

Flagging Patterns in Request Lines

SQLMediumMid level~15 min

Problem

Table: `request_log`

```text
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| line_id | int |
| path_text | varchar |
| service | varchar |
+-------------+---------+
line_id is the primary key for this table.
Each row holds one captured request path and the service that emitted it.
```

A reliability team wants four diagnostic flags computed for every captured request line, based on its `path_text`:

- `is_api`: 1 if the path begins with `/api`.
- `is_versioned`: 1 if the path ends with `v1`, `v2`, or `v3`.
- `has_admin`: 1 if the path contains the substring `admin`.
- `has_double_slash`: 1 if the path contains three or more consecutive slashes (`///`).

Return every row from `request_log` together with the four flag columns, ordered by `line_id`.

Tables

Example rows — the live problem includes the full dataset.

request_log
line_idpath_textservice
1/api/users/list/v2gateway
2////healthgateway
3/admin/panel/homeconsole

Expected output

Your answer should return 7 rows with the columns line_id, path_text, service, is_api, is_versioned, has_admin, has_double_slash.

Starter code (SQL)

SELECT *
FROM request_log;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions