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
Latest KYC Event Status and Risk Classification
00:00
5 left

Latest KYC Event Status and Risk Classification

MediumSQL · PostgreSQL

Problem

From this sample data, perform the necessary transformation to achieve a desirable end state.

Use raw_kyc_events and source_systems. Return the latest valid event for each subject, normalize its status, classify its risk score, and retain subjects whose source reference has no matching source record.

Output

  1. One row per non-null subject reference.
  2. Columns: subject_ref, source_name, observed_at, normalized_status, risk_tier, and risk_score.
  3. Use Unknown source for unmatched or null sources and unclassified for null or unrecognized statuses.
  4. Order by subject_ref ascending.

Output details

  • Treat every event as eligible; select the greatest observed_at, breaking ties by greatest event_id.
  • Normalize statuses by lowercasing them; recognize only active, cleared, closed, escalated, pending, and rejected.
  • Classify risk_score as high for values at least 80, medium for values from 50 through 79, and low below 50.
  • Classify a null risk_score as unknown.

Schema

raw_kyc_events
ColumnTypeDescription
event_idPKINTUnique event identifier
subject_refVARCHAR(30)External subject reference
source_idINTReference to the originating source system
observed_atTIMESTAMPTime when the event was observed
raw_statusVARCHAR(30)Unnormalized source status
risk_scoreNUMERIC(5,2)Numeric risk score
source_systems
ColumnTypeDescription
source_idPKINTUnique source system identifier
source_nameVARCHAR(80)Display name of the source system
Tablesraw_kyc_eventssource_systems
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two tables are in the Question tab.

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.