LeetCode 183: Customers Who Never Order

Database

Problem Description

Explanation:

To solve this problem, we need to find customers who never placed an order. We can achieve this by using a LEFT JOIN operation between the Customers and Orders tables and then filtering out the customers who have NULL values in the Orders table.

Algorithmic Idea:

  1. Perform a LEFT JOIN operation between the Customers and Orders tables using the customerId column.
  2. Filter out the customers who have NULL values in the customerId column from the Orders table.
  3. Return the names of customers who never placed an order.

Time Complexity:

The time complexity of this solution is O(n), where n is the number of rows in the Customers table.

Space Complexity:

The space complexity of this solution is O(n), where n is the number of rows in the Customers table.


:

Solutions

# Java Solution
SELECT c.name AS Customers
FROM Customers c
LEFT JOIN Orders o ON c.id = o.customerId
WHERE o.customerId IS NULL;

Loading editor...