Procurement & Sourcing Analytics · Mission 6 of 30Easy

Spend by category

GROUP BY with SUM aggregation

The Brief

Maya ChenProcurement Directorprocurement-ops

Roll up total invoice spend by category. Join `fact_invoices` to `fact_purchase_orders` on po_id, then to `dim_categories`. Show category_name, total_spend descending.

You'll practice

GROUP BYJOINSUM

Tables & columns available

fact_invoicesfact7 columns
ColumnTypeKey
invoice_idINTPK
po_idINTFK → fact_purchase_orders
supplier_idINTFK → dim_suppliers
invoice_dateTEXT
invoice_amountREAL
po_amountREAL
payment_dateTEXT
fact_purchase_ordersfact15 columns
ColumnTypeKey
po_idINTPK
supplier_idINTFK → dim_suppliers
category_idINTFK → dim_categories
contract_idINTFK → dim_contracts
req_dateTEXT
po_dateTEXT
ack_dateTEXT
asn_dateTEXT
gr_dateTEXT
invoice_dateTEXT
qty_orderedINT
qty_receivedINT
unit_priceREAL
contracted_priceREAL
statusTEXT
dim_categoriesdim4 columns
ColumnTypeKey
category_idINTPK
category_nameTEXT
category_managerTEXT
spend_typeTEXT

Hints (3)

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

Hint 1

Spend lives on invoices but category lives on the PO header — bridge them through purchase orders.

Hint 2

JOIN to dim_categories on category_id.

Hint 3

GROUP BY category_name, sum invoice_amount, ORDER BY DESC.