LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Reporting in SQL

Kurs anzeigen

Anleitung zur Übung

  • 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.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

-- 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 bearbeiten und ausführen