easy +10 pts

Customers Never Order

Find customers who have never placed an order using SQLite.

You are given an in-memory SQLite database with two tables: ```sql CREATE TABLE Customers ( id INTEGER PRIMARY KEY, name TEXT NOT NULL ); CREATE TABLE Orders ( id INTEGER PRIMARY KEY, customerId INTEGER NOT NULL, FOREIGN KEY (customerId) REFERENCES Customers(id) ); ``` Write a function `customers_with_no_orders(db_path, customers, orders)` that: - If `db_path` is None, connect to an in-memory database; otherwise connect to the SQLite file at `db_path`. - Create the two tables inside the function, then insert the provided `customers` (list of `(id, name)` tuples) and `orders` (list of `(order_id, customer_id)` tuples). - Execute a SQL query that returns every customer who has never placed an order. - The result must be a list of tuples, each with exactly one element: the customer name. - The list must be sorted by `name` ascending (using SQLite's default ordering). - If no customer matches, return `None`. Use the `sqlite3` module. The function signature is: ```python def customers_with_no_orders(db_path, customers, orders): ... ``` Your implementation must create the tables and insert the data itself. The query should work for any number of rows, not just the provided examples.

Constraints

- `customers` is a list of tuples `(id, name)` where `id` is an integer and `name` is a non-empty string. - `orders` is a list of tuples `(order_id, customer_id)` where both are integers. - All ids are unique within their own table. Every `customer_id` in `orders` refers to an existing customer id. - The total number of customers and orders is at most 10,000. - The function should return a list of tuples, each with exactly one string element (the customer name). - The result must be sorted by `name` ascending (SQLite default byte order). - If no customer matches, return `None`.

Example

```python
>>> customers_with_no_orders(None, [(1, 'Alice'), (2, 'Bob'), (3, 'Charlie')], [(101, 1), (102, 2)])
[('Charlie',)]

>>> customers_with_no_orders(None, [(1, 'Alice')], [])
[('Alice',)]

>>> customers_with_no_orders(None, [(1, 'Alice'), (2, 'Bob')], [(1, 1), (2, 2)])
None
```
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use a LEFT JOIN between Customers and Orders, then filter where Orders.id IS NULL.
Alternatively, use NOT IN with a subquery: SELECT name FROM Customers WHERE id NOT IN (SELECT customerId FROM Orders).
Order the result with ORDER BY name.
Don't forget to close the connection after fetching results.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.