Quick Commerce Analytics Path · Mission 4 of 25Easy

Substitution volume

Count rows on a fact table with a WHERE filter and a GROUP BY. Practice reading the denormalized merchant_id on fact_substitutions so no join is needed yet.

Back to Quick Commerce Analytics

The Brief

Tomas WolfeCustomer Experience Leadcx

Support tickets about swaps are climbing. I want substitution volume per merchant, but only the ones the customer actually approved (customer_approved = 1) since those are the real swaps. fact_substitutions carries merchant_id directly. Columns: merchant_id, substitution_count. ORDER BY substitution_count DESC, merchant_id ASC.

You'll practice

WHERECOUNTGROUP BY merchant

Tables & columns available

fact_substitutionsfact11 columns
ColumnTypeKey
substitution_idINTPK
order_idINTFK → fact_orders
merchant_idINTFK → dim_merchants
shopper_idINTFK → dim_shoppers
sub_tsTEXT
original_item_priceREAL
sub_item_priceREAL
customer_chargedREAL
merchant_paidREAL
reasonTEXT
customer_approvedINT

Hints (3)

Each hint you reveal reduces the XP you can earn. Try the query first.

Hint 1

fact_substitutions has its own merchant_id, so you can count without joining.

Hint 2

Filter with WHERE customer_approved = 1, then GROUP BY merchant_id.

Hint 3

Order by substitution_count descending with merchant_id as the tiebreaker so the worst offenders lead, and double-check the customer_approved = 1 filter is still in place or rejected swaps sneak into the count.