Write a query to identify users who scanned receipts from the same retailer within a five-minute window, indicating potential fraud at Fetch.
Use the provided scan records and consider consecutive scans by the same user at the same retailer. Exclude scans with missing timestamps or unmatched users and retailers.
Output
- One row per qualifying consecutive scan pair
- Include
user_id, user_name, retailer_id, retailer_name, both scan IDs and timestamps, and seconds_between
- Order by
user_id, then the later scan timestamp, then the later scan ID