Device Velocity Counts
Start Timer
0:00:00
Let’s say we work at Socure on identity fraud models, and the applications table has one row per application with a fingerprint of the device that submitted it. Fraud rings often submit many applications from the same device in a short burst, so write a query that returns, for every application, the number of applications from the same device in the ten minutes before it.
Rules
- Count applications created at or after created_at minus 10 minutes and strictly before created_at, so an application never counts itself or another one with the exact same created_at.
- created_at is never NULL and has whole-second precision.
- Applications with a NULL device_id get 0.
- Order by application_id.
Example:
Input:
applications table
| Column | Type |
|---|---|
application_id |
INTEGER |
client_id |
INTEGER |
device_id |
VARCHAR |
created_at |
DATETIME |
Output:
| Column | Type |
|---|---|
application_id |
INTEGER |
device_id |
VARCHAR |
apps_prev_10min |
INTEGER |
.
.
.
.
.
.
.
.
.
Comments