Sales Analysis: Specific Product

ASKED IN INTERVIEW
2pts
Apple

Problem Statement

Apple marketing wants to target "iPhone-only" users with a special MacBook promotion.

Write an SQL query to find all buyer_id values for users who have bought the product named iPhone but have never bought the product named MacBook.

Rules:

  • The product names are case-sensitive.
  • Output columns: buyer_id.
  • Results must be sorted by buyer_id in ascending order.
Tests your understanding of
Subqueries, Set Operations and Filtering

Input Tables

sales
sale_id(INTEGER)product_id(INTEGER)buyer_id(INTEGER)sale_date(DATE)
110112026-01-01
210122026-01-02
310222026-01-03
410132026-01-04
products
product_id(INTEGER)product_name(VARCHAR)
101iPhone
102MacBook
103AirPods
product_category
product_id(INTEGER)category(VARCHAR)
101Mobile
102Laptop

Expected Output

buyer_id(INTEGER)
1
3

Tags

EasyASKED IN INTERVIEWSubqueriesSet OperationsFiltering
10-15 min
68%

Hints