Brightlane's operations team is reviewing the active order pipeline and wants to exclude anything that has already reached a terminal state.
Write a query to return the ID, status, and total amount for every order that is neither delivered nor cancelled.
Assumptions:
- The
orderstable contains every order Brightlane has processed. - Terminal statuses are
deliveredandcancelled; every other value ofstatusrepresents an order still in the active pipeline.
Output:
- One row per non-terminal order, with columns
id,status, andtotal_amount.
Schema · ecommerce 5 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
id,
status,
total_amount
FROM
orders
WHERE
status NOT IN ('delivered', 'cancelled') The shape
NOT IN ('delivered', 'cancelled') inverts the membership test — the active pipeline is everything except the two terminal statuses, so the filter names what to exclude and lets every other status through.
Clause by clause
SELECT id, status, total_amountreturns the three columns the operations review needs: the order identifier, the current status so the team can see where each order sits in the pipeline, and the dollar amount that quantifies the active queue.FROM ordersreads the order table.WHERE status NOT IN ('delivered', 'cancelled')keeps only the rows whosestatusis neitherdeliverednorcancelled. The result is the inverse of the membership test —pendingorders pass,shippedorders pass, anything else that isn't terminal passes.
The trap
If a NOT IN list ever contains a NULL, the whole condition evaluates to unknown for every row and the result set comes back empty. The list here is hard-coded strings only, so the trap doesn't fire, but the rule is: keep NULL out of any NOT IN list.
You practiced inverting a membership test with NOT IN. status NOT IN ('delivered', 'cancelled') is the compact form of "none of these values" — the recurring shape behind every exclusion filter against a known list of terminal or excluded states.