Complex~32min

The Discount Stacking That Bypasses the Cap

8 orders have 3 separate discount codes stacked — app promo, loyalty points, birthday coupon — summing to 37% of the subtotal, over the documented 30% max-discount policy. Each code was applied by a different system with no idea the others had already fired. 15 more orders have a single discount over 30% on its own, but it's a manager_comp code, explicitly exempt from the stacking cap.

Tables you'll query

ordersorder_discounts

What you'll learn

CTEs (WITH clause)Window FunctionsAggregations & GROUP BY
Investigate this case →