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.
Este exercício faz parte do curso
Reporting in SQL
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
-- 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 ____;