Deals Of The Week - 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 (category_id 6 or 8) and vegetarian categories (all other category_id values)? Show two columns: product_type (either 'vegetarian' or 'non-vegetarian') and avg_product_count.

Stuck? Here's a hint!

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