The analytics team wants to know what percentage of orders are worth $250 or less.
Using the orders table, return the percentage of all orders whose amount_usd is at or below 250. This represents the percentile rank of a $250 order. Report it as a number from 0 to 100: for example, return 80 for 80%, not 0.8.
Ordering: Return a single row; sorting is not required.
Returnpercentile_rank
About this problem
You practise turning a conditional count into a share. The analytics team wants the percentage of orders in orders whose amount_usd is at or below 250, reported as a single percentile_rank value on a 0–100 scale. The skill is dividing a count of matching rows by a count of all rows in one aggregate query, and producing the number in the units the prompt asks for.
Several things commonly go wrong. First, the COUNT(CASE … ELSE 0 END) slip counts every row as a match, because COUNT counts any value that isn’t NULL and 0 is a value, so the answer comes out as 100. Second, integer division: in some engines a count divided by a count is truncated to a whole number, so a share such as 0.6 becomes 0 before you multiply by 100. Third, the edge: the prompt says “at or below”, and the sample includes an order of exactly 250, so a strict < leaves it out and gives a lower figure that still looks believable. Finally, the prompt asks for the 0–100 scale; returning a fraction gives a different number even when the share is right.
Read the lesson: Conditional Aggregation (P06) →