Business Intelligence Path · Mission 7 of 31Easy

Which categories are actually selling well?

Use HAVING to filter aggregated groups and COUNT(DISTINCT) for unique counts

Back to Business Intelligence

The Brief

Priya NairHead of Productproduct-analytics

I'm prepping for a SKU rationalization review — we want to consolidate slow-moving categories. For each product category (normalized, one row per category), show the number of distinct products we carry and the total sales transaction count. Only include categories with more than 400 transactions — those are the ones earning their place on the shelf. The ones below 400 are candidates to prune, but that's a separate conversation.

You'll practice

HAVINGCOUNT DISTINCT

Tables & columns available

fact_salesfact8 columns
ColumnTypeKey
sale_idINTPK
employee_idINTFK → dim_employees
product_idINTFK → dim_products
region_idINTFK → dim_regions
sale_dateTEXT
quantityINT
revenueREAL
discountREAL
dim_productsdim5 columns
ColumnTypeKey
product_idINTPK
product_nameTEXT
categoryTEXT
unit_priceREAL
launch_dateTEXT

Hints (3)

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

Hint 1

There's a casing inconsistency in the category column that will cause your GROUP BY to split what should be a single category into multiple rows. Normalize it before grouping.

Hint 2

Use COUNT(*) for total transactions and COUNT(DISTINCT product_id) for unique products

Hint 3

HAVING COUNT(*) > 400 filters after aggregation — WHERE cannot filter on aggregates