Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Basic CTE
11. Multiple CTEs – practice 2
Summary

Instruction

Excellent. Now, let's do another kind of exercise with multiple CTEs where you will have to use a JOIN in the outer query.

Exercise

For each person who made donations in 'music' or 'traveling' categories, show three columns:

  • supporter_id,
  • min_music – that person's minimum donation amount in the 'music' category,
  • max_traveling – that person's maximum donation amount in the 'traveling' category.

Stuck? Here's a hint!

First, you should use CTE to find all users that donated to either 'music' or 'traveling' projects. Then, use two CTEs, one for finding the minimum for 'music' category, the other one for finding the maximum in 'traveling' category. In each CTE, select the supporter_id as well. In the outer query, join all your CTEs results on the supporter_id.

In order to show all the results use LEFT JOIN.