Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Receipt Fraud Window Detection
00:00
5 left

Receipt Fraud Window Detection

MediumSQL · PostgreSQL

Problem

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

  1. One row per qualifying consecutive scan pair
  2. Include user_id, user_name, retailer_id, retailer_name, both scan IDs and timestamps, and seconds_between
  3. Order by user_id, then the later scan timestamp, then the later scan ID

Output details

  • Return columns in this order: user_id, user_name, retailer_id, retailer_name, earlier_scan_id, later_scan_id, earlier_scanned_at, later_scanned_at, seconds_between.
  • Treat the five-minute window as inclusive, allowing intervals exactly equal to 5 minutes.
  • Order scans within each user and retailer by scanned_at ascending, breaking timestamp ties with scan_id ascending.
  • Round seconds_between to the nearest whole second and return it as an integer.
  • Sort the final results by user_id, later_scanned_at, and later_scan_id, all ascending.

Schema

users
ColumnTypeDescription
user_idPKINTFetch user identifier
user_nameVARCHAR(100)User display name
retailers
ColumnTypeDescription
retailer_idPKINTRetailer identifier
retailer_nameVARCHAR(120)Retailer display name
receipt_scans
ColumnTypeDescription
scan_idPKINTReceipt scan identifier
user_idINTUser who scanned the receipt
retailer_idINTRetailer associated with the receipt
scanned_atTIMESTAMPTZTimestamp when the receipt was scanned
Tablesusersretailersreceipt_scans
Interviewer

Your question is Receipt Fraud Window Detection. Start with the requirements and the three tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.