The 250 Club
- O(n) · Medium
- Full plan
- SQL
- grouping
- joins
- decimals
Problem
The store is starting a club for its best customers. You're in once your orders add up to more than 250, where each order counts for its product's price times the units ordered. One big order or several small ones, it makes no difference, and exactly 250 doesn't get you in yet.
The membership card has the customer number on it. Show the customer_id and then that customer's total, rounded to 2 decimals. The order dated the 20th has the day mistyped, but the order was placed: its money counts.
What it has to return
These rows, in any order
| customer_id | total |
|---|---|
| 1 | 299.9 |
| 2 | 797.5 |
| 6 | 958.9 |
This is what comes out with the data in the practice database this challenge uses. The column names don’t count, so name yours however you like: what counts is how many there are and the order they come in. Besides this one, the challenge has hidden tests with other data that are revealed when you submit your solution.
You start with this
SQL
SELECT o.customer_id, p.price
FROM orders o
JOIN products p
ON o.product_id = p.idIt opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.
More O(n) challenges
- The notebook by the registerSQL · grouping · joins
- What the team makesSQL · grouping · joins · decimals
- Where are the books from?SQL · grouping · joins · sorting
- Where do our orders come from?SQL · grouping · joins · nulls
- Where there's more than oneSQL · grouping · nulls
- Who owes grades?SQL · grouping · joins · nulls