Introduction
Basic CTEs
11. Multiple CTEs – practice 2
Summary

Instruction

Excellent. Now, let's do another kind of exercise with multiple CTEs. In this one, you will have to use an INNER JOIN in the outer query.

Exercise

For each person who made donations in the N'music' or N'travelling' categories, show these three columns:

  • SupporterId,
  • MinMusic – that person's minimum donation amount in the music category,
  • MaxTravelling – that person's maximum donation amount in the travelling category.

Stuck? Here's a hint!

First, you should use a CTE to find all users that donated to either music or travelling projects. Then, use two CTEs: one for finding the minimum for the music category, the other one for finding the maximum for the travelling category. In each CTE, select the SupporterId as well. In the outer query, join all your CTE results on SupporterId. In order to show all the results, use LEFT JOIN.