LoslegenKostenlos loslegen

Troubleshooting CASE statements

In the previous exercise, you may have noticed several null values in our case statement, which can indicate there is an issue with the code.

In these instances, it's worth investigating to understand why these null values are appearing. In this exercise, you will go through a series of steps to identify the issue and make changes to the code where necessary.

Diese Übung ist Teil des Kurses

Reporting in SQL

Kurs anzeigen

Interaktive Übung

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

-- Query from last exercise shown below.  Comment it out.
SELECT 
	sport,
    CASE WHEN weight/height^2*100 <.25 THEN '<.25'
    WHEN weight/height^2*100 <=.30 THEN '.25-.30'
    WHEN weight/height^2*100 >.30 THEN '>.30' END AS bmi_bucket,
    COUNT(DISTINCT athlete_id) AS athletes
FROM summer_games AS s
JOIN athletes AS a
ON s.athlete_id = a.id
GROUP BY sport, bmi_bucket
ORDER BY sport, athletes DESC;

-- Show height, weight, and bmi for all athletes
SELECT 
	____,
    ____,
    ____ AS bmi
FROM ____
-- Filter for NULL bmi values
WHERE ____;
Code bearbeiten und ausführen