Successful Logins from Multiple Countries
Problem statement
You are given a table login_attempts with columns user_id (text), timestamp (timestamp), status (text), and country (text).
Return the users who have at least one SUCCESS login from each of at least two different countries. Only successful logins count, and repeated logins from one country still count as one country.
The result must have exactly one column named user_id, sorted alphabetically, with each qualifying user returned once. Consider every input row; there is no time-window filter.
Table schema
MySQLPostgreSQLPandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
login_attempts
| Column | Type | Nullable | Description |
|---|---|---|---|
| user_id | Text | No | — |
| timestamp | Timestamp | No | — |
| status | Text | No | — |
| country | Text | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| user_id | Text | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- The table contains between
0and1000rows. Duplicate rows are allowed. - All input values are non-null.
- User IDs contain only lowercase English letters. Countries are represented by two uppercase English letters.
statusis eitherSUCCESSorFAILURE. Timestamps are valid timestamps and do not affect qualification.