Attach the Credit Limit in Effect at Each Card Transaction

Last updated: November 29, 2026

Quick Overview

Given a credit limit history table with effective timestamps and a transactions table, return each transaction with the credit limit that was in effect when it occurred, so utilization can be computed at transaction time.

Capital One
Data Manipulation (SQL/Python)
Data Scientist
Capital One
November 29, 2026
Data Scientist
Onsite
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given a credit limit history table with effective timestamps and a transactions table, return each transaction with the credit limit that was in effect when it occurred, so utilization can be computed at transaction time.

Capital One regularly changes credit lines through proactive line increases and risk-driven decreases, so models that use utilization need the limit as of each event, not today's limit. The interviewer checks point-in-time (as-of) joins and whether you recognize the leakage that a current-limit join introduces.

What the Interviewer Expects
  • Builds validity intervals with LEAD over effective timestamps
  • Uses a half-open interval join so each transaction matches exactly one limit
  • Handles transactions before the first recorded limit
  • Offers pandas merge_asof as an alternative
  • Explains why joining the current limit leaks future information into features
Key Topics to Cover
as-of join
point-in-time correctness
LEAD
merge_asof
SCD type 2
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you handle two limit changes with the same effective timestamp?
  • How does this generalize to slowly changing dimension type 2 tables?
  • How would you compute average utilization over a statement cycle with limit changes mid-cycle?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data
  • credit_limit_history(account_id, effective_ts, credit_limit): one row per change, including the initial limit at account open.
  • card_transactions(txn_id, account_id, txn_ts, amount).
  • A change...
Approach

Turn history into intervals [valid_from, valid_to) using LEAD(effective_ts). Join transactions where txn_ts >= valid_from AND (valid_to IS NULL OR txn_ts < valid_to). Half-open intervals guarant...


Submit Your Answer
Markdown supported