PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Data Manipulation (SQL/Python)/Capital One

Write SQL for lowest price with ratings

Last updated: Mar 29, 2026

Quick Overview

This question evaluates SQL data-manipulation skills including aggregation, conditional filtering, NULL handling, grouping, and deterministic ordering, and sits in the Data Manipulation (SQL/Python) domain with an emphasis on practical application of query writing rather than purely conceptual design.

  • Medium
  • Capital One
  • Data Manipulation (SQL/Python)
  • Data Scientist

Write SQL for lowest price with ratings

Company: Capital One

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: Medium

Interview Round: Technical Screen

You have two tables. Schema: - products(product_id INT PRIMARY KEY, product_name TEXT, category TEXT) - purchase(purchase_id INT PRIMARY KEY, product_id INT, price DECIMAL(10,2), stars INT NULL) Goal: For every category present in products, return the lowest price among purchases for products in that category that have at least one rating (stars) > 4. If a category has no qualifying purchase (no rows with stars > 4), output 0 for its price. Null stars do not qualify. Return columns: category, price. One row per category. Deterministic sorting by category ASC. Sample data (ASCII): products product_id | product_name | category 1 | iPhone 14 | Apple 2 | MacBook Air | Apple 3 | Banana Phone | Banana 4 | Pear X | Pear 5 | Orange Z | Orange purchase purchase_id | product_id | price | stars 10 | 1 | 999.00 | 5 11 | 1 | 1099.00| 3 12 | 2 | 1299.00| 4 13 | 3 | 49.00 | 5 14 | 3 | 39.00 | 2 15 | 4 | 199.00 | 4 16 | 4 | 179.00 | NULL 17 | 5 | 299.00 | NULL Expected output on the sample: category | price Apple | 999.00 Banana | 49.00 Orange | 0 Pear | 0 Write a single SQL query (PostgreSQL or MySQL compatible) that produces the required output on all inputs, handling: categories with no purchases at all; multiple qualifying purchases per category; and ensuring numeric 0 (not NULL) when no stars > 4 exist.

Quick Answer: This question evaluates SQL data-manipulation skills including aggregation, conditional filtering, NULL handling, grouping, and deterministic ordering, and sits in the Data Manipulation (SQL/Python) domain with an emphasis on practical application of query writing rather than purely conceptual design.

Related Interview Questions

  • Clean and Merge Housing Data - Capital One (easy)
  • Find Lowest Prices for Highly Rated Categories - Capital One (medium)
  • Write SQL to compute campaign net revenue - Capital One (Medium)
  • Merge CSVs and build revenue pivot with pandas - Capital One (Medium)
  • Find top category per region in Aug 2025 - Capital One (Medium)
Capital One logo
Capital One
Oct 13, 2025, 9:49 PM
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
1
0

You have two tables. Schema:

  • products(product_id INT PRIMARY KEY, product_name TEXT, category TEXT)
  • purchase(purchase_id INT PRIMARY KEY, product_id INT, price DECIMAL(10,2), stars INT NULL) Goal: For every category present in products, return the lowest price among purchases for products in that category that have at least one rating (stars) > 4. If a category has no qualifying purchase (no rows with stars > 4), output 0 for its price. Null stars do not qualify. Return columns: category, price. One row per category. Deterministic sorting by category ASC. Sample data (ASCII): products product_id | product_name | category 1 | iPhone 14 | Apple 2 | MacBook Air | Apple 3 | Banana Phone | Banana 4 | Pear X | Pear 5 | Orange Z | Orange

purchase purchase_id | product_id | price | stars 10 | 1 | 999.00 | 5 11 | 1 | 1099.00| 3 12 | 2 | 1299.00| 4 13 | 3 | 49.00 | 5 14 | 3 | 39.00 | 2 15 | 4 | 199.00 | 4 16 | 4 | 179.00 | NULL 17 | 5 | 299.00 | NULL Expected output on the sample: category | price Apple | 999.00 Banana | 49.00 Orange | 0 Pear | 0 Write a single SQL query (PostgreSQL or MySQL compatible) that produces the required output on all inputs, handling: categories with no purchases at all; multiple qualifying purchases per category; and ensuring numeric 0 (not NULL) when no stars > 4 exist.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Data Manipulation (SQL/Python)•More Capital One•More Data Scientist•Capital One Data Scientist•Capital One Data Manipulation (SQL/Python)•Data Scientist Data Manipulation (SQL/Python)
PracHub

Master your tech interviews with 7,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.