Total Spend on Other Products by Customers Who Bought Photoshop

Quick Overview

Write a SQL query that finds the customers who bought Photoshop and totals what each of them spent on every other product. It tests IN subqueries, filtering rows before aggregation, and avoiding double counting when a customer has several qualifying orders.

Total Spend on Other Products by Customers Who Bought Photoshop

Company: Adobe

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

Each row of `orders` is one purchase. For every customer who bought Photoshop at least once, return the total `amount` that customer spent on products other than Photoshop. Use a subquery to identify the Photoshop customers, and leave out any Photoshop customer who has no non-Photoshop purchase. ```hint Two jobs for the same table A customer's Photoshop rows decide whether the customer qualifies, and the other rows are what you add up. Keep those two filters apart. ``` ### Input Table(s) Table `orders` | Column | Type | Meaning | |---|---|---| | order_id | INT | Id of the order row. Primary key. | | customer_id | INT | Customer who placed the order. NOT NULL. | | product | VARCHAR(100) | Product name, such as `Photoshop`. NOT NULL. | | amount | DECIMAL(10,2) | Amount paid for this order. NOT NULL. | Primary key: `order_id`. A customer can have many rows, including several Photoshop rows. ### Output Contract - Columns, in this order: `customer_id`, `total_other_spend`. - One row per customer who has at least one Photoshop order and at least one non-Photoshop order. - `total_other_spend` is the sum of `amount` over that customer's non-Photoshop orders, kept at the column's two decimals with no further rounding. - Order by `customer_id` ascending. Each customer appears once, so this ordering is unique. ### Example Input `orders`: | order_id | customer_id | product | amount | |---|---|---|---| | 1 | 101 | Photoshop | 120.00 | | 2 | 101 | Illustrator | 80.00 | | 3 | 101 | Lightroom | 40.00 | | 4 | 102 | Photoshop | 120.00 | | 5 | 103 | Illustrator | 80.00 | | 6 | 104 | Photoshop | 60.00 | | 7 | 104 | Photoshop | 60.00 | | 8 | 104 | Premiere Pro | 24.00 | Expected output: | customer_id | total_other_spend | |---|---| | 101 | 120.00 | | 104 | 24.00 | Customer 101 bought Photoshop and spent 80.00 + 40.00 on other products. Customer 102 bought only Photoshop, so it is left out. Customer 103 never bought Photoshop. Customer 104 has two Photoshop orders, and its other spend is still 24.00, counted once. ### Constraints and Clarifications - `orders` has at most 10,000 rows. - `product` is never empty and `amount` is never negative. None of the columns is NULL. - Product matching is exact: only rows where `product = 'Photoshop'` count as Photoshop purchases. - A Photoshop customer whose only other purchases have `amount` 0.00 still bought another product, so that customer appears with 0.00. - Duplicate products are fine. Two Illustrator orders from the same customer both count toward the total.

Overview: Write a SQL query that finds the customers who bought Photoshop and totals what each of them spent on every other product. It tests IN subqueries, filtering rows before aggregation, and avoiding double counting when a customer has several qualifying orders.

Adobe logo
Adobe
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

Each row of orders is one purchase. For every customer who bought Photoshop at least once, return the total amount that customer spent on products other than Photoshop. Use a subquery to identify the Photoshop customers, and leave out any Photoshop customer who has no non-Photoshop purchase.

Input Table(s)

Table orders

ColumnTypeMeaning
order_idINTId of the order row. Primary key.
customer_idINTCustomer who placed the order. NOT NULL.
productVARCHAR(100)Product name, such as Photoshop. NOT NULL.
amountDECIMAL(10,2)Amount paid for this order. NOT NULL.

Primary key: order_id. A customer can have many rows, including several Photoshop rows.

Output Contract

  • Columns, in this order: customer_id , total_other_spend .
  • One row per customer who has at least one Photoshop order and at least one non-Photoshop order.
  • total_other_spend is the sum of amount over that customer's non-Photoshop orders, kept at the column's two decimals with no further rounding.
  • Order by customer_id ascending. Each customer appears once, so this ordering is unique.

Example

Input orders:

order_idcustomer_idproductamount
1101Photoshop120.00
2101Illustrator80.00
3101Lightroom40.00
4102Photoshop120.00
5103Illustrator80.00
6104Photoshop60.00
7104Photoshop60.00
8104Premiere Pro24.00

Expected output:

customer_idtotal_other_spend
101120.00
10424.00

Customer 101 bought Photoshop and spent 80.00 + 40.00 on other products. Customer 102 bought only Photoshop, so it is left out. Customer 103 never bought Photoshop. Customer 104 has two Photoshop orders, and its other spend is still 24.00, counted once.

Constraints and Clarifications

  • orders has at most 10,000 rows.
  • product is never empty and amount is never negative. None of the columns is NULL.
  • Product matching is exact: only rows where product = 'Photoshop' count as Photoshop purchases.
  • A Photoshop customer whose only other purchases have amount 0.00 still bought another product, so that customer appears with 0.00.
  • Duplicate products are fine. Two Illustrator orders from the same customer both count toward the total.