Aan de slagGa gratis aan de slag

JOIN then UNION query

Your goal is to create a report with the following fields:

  • season, which outputs either summer or winter
  • 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.

Deze oefening maakt deel uit van de cursus

Reporting in SQL

Cursus bekijken

Oefeninstructies

  • Setup a query that shows unique events by country and season for summer events.
  • Setup a similar query that shows unique events by country and season for winter events.
  • Combine the two queries using a UNION ALL.
  • Sort the report by events in descending order.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

-- 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 ____;
Code bewerken en uitvoeren