PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Capital One

Write SQL using joins and window functions

Last updated: Apr 30, 2026

Quick Overview

This question evaluates proficiency in SQL joins, aggregation, and window functions for ranked group-level analytics, specifically testing the ability to compute partitioned ranks, handle ties, and apply time-based filters in a data engineering context.

  • medium
  • Capital One
  • Coding & Algorithms
  • Data Engineer

Write SQL using joins and window functions

Company: Capital One

Role: Data Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## SQL Coding: Rank within Groups with Joins You are given two tables: ### `accounts` - `account_id` (string) - `customer_id` (string) - `segment` (string) — e.g., `"prime"`, `"subprime"` ### `transactions` - `transaction_id` (string) - `account_id` (string) - `amount` (numeric) - `txn_ts` (timestamp) ### Task For each `segment`, find the **top 3 customers by total transaction amount** in the last **30 days** (inclusive). Requirements: - A customer may have **multiple accounts**; include all their accounts’ transactions. - Use appropriate **JOINs** to connect transactions to segments. - Use a **window function** to compute the rank **within each segment**. - If there are ties at rank 3, include **all** tied customers. ### Output Return columns: - `segment` - `customer_id` - `total_amount_30d` - `rank_in_segment` Order results by `segment`, then `rank_in_segment`, then `customer_id`.

Quick Answer: This question evaluates proficiency in SQL joins, aggregation, and window functions for ranked group-level analytics, specifically testing the ability to compute partitioned ranks, handle ties, and apply time-based filters in a data engineering context.

Related Interview Questions

  • Solve Four Coding Assessment Tasks - Capital One (medium)
  • Review Preprocessing Code and Tests - Capital One (easy)
  • Remove nodes with a given value - Capital One (medium)
  • Solve multiple algorithmic interview questions - Capital One (hard)
  • Place Pieces on a Grid - Capital One (medium)
Capital One logo
Capital One
Mar 1, 2026, 12:00 AM
Data Engineer
Technical Screen
Coding & Algorithms
23
0

SQL Coding: Rank within Groups with Joins

You are given two tables:

accounts

  • account_id (string)
  • customer_id (string)
  • segment (string) — e.g., "prime" , "subprime"

transactions

  • transaction_id (string)
  • account_id (string)
  • amount (numeric)
  • txn_ts (timestamp)

Task

For each segment, find the top 3 customers by total transaction amount in the last 30 days (inclusive).

Requirements:

  • A customer may have multiple accounts ; include all their accounts’ transactions.
  • Use appropriate JOINs to connect transactions to segments.
  • Use a window function to compute the rank within each segment .
  • If there are ties at rank 3, include all tied customers.

Output

Return columns:

  • segment
  • customer_id
  • total_amount_30d
  • rank_in_segment

Order results by segment, then rank_in_segment, then customer_id.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Capital One•More Data Engineer•Capital One Data Engineer•Capital One Coding & Algorithms•Data Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.