JOIN then UNION query
Your goal is to create a report with the following fields:
- season, which outputs either
summer
orwinter
- country
- events, which shows the unique number of events
There are multiple ways to create this report. In this exercise, create the report by using the JOIN
first, UNION
second approach.
As always, feel free to reference your E:R Diagram to identify relevant fields and tables.
This exercise is part of the course
Reporting in SQL
Exercise instructions
- Setup a query that shows unique
events
bycountry
andseason
for summer events. - Setup a similar query that shows unique
events
bycountry
andseason
for winter events. - Combine the two queries using a
UNION ALL
. - Sort the report by events in descending order.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
-- Query season, country, and events for all summer events
SELECT
____ AS season,
____,
____ AS events
FROM ____ AS s
JOIN ____ AS c
ON ____
GROUP BY ____
-- Combine the queries
____
-- Query season, country, and events for all winter events
SELECT
____ AS season,
____,
____ AS events
FROM ____ AS w
JOIN ____ AS c
ON ____
GROUP BY ____
-- Sort the results to show most events at the top
ORDER BY ____;