Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
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'traveling' categories, show these three columns:

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

Stuck? Here's a hint!

First, you should use a CTE to find all users that donated to either music or traveling projects. Then, use two CTEs: one for finding the minimum for the music category, the other one for finding the maximum for the traveling 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.