Summer Deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Basic multi-level aggregation
Multi-level aggregation in groups
Multi-level aggregation with custom classification
12. Multi-level aggregation with CASE WHEN – exercise
Three or more aggregation levels
Summary

Instruction

Good job! Let's do one more exercise before we go to the next kind of multi-level aggregation.

Exercise

What is the average number of products in non-vegetarian (CategoryID 6 or 8) and vegetarian categories (all other CategoryID values)? Show two columns: ProductType (either N'vegetarian' or N'non-vegetarian') and AvgProductCount.

Stuck? Here's a hint!

In the inner query, create a CASE WHEN expression to check the CategoryID value and show either N'non-vegetarian' or N'vegetarian'. Then, in the outer query, use that column with the AVG() function. You need to use only one table – Products.