LoslegenKostenlos loslegen

Fixing calculations with coalesce

Null values impact aggregations in a number of ways. One issue is related to the AVG() function. By default, the AVG() function does not take into account any null values. However, there may be times when you want to include these null values in the calculation as zeros.

To replace null values with a string or a number, use the COALESCE() function. Syntax is COALESCE(fieldName,replacement), where replacement is what should replace all null instances of fieldName.

This exercise will walk you through why null values can throw off calculations and how to troubleshoot these issues.

Diese Übung ist Teil des Kurses

Reporting in SQL

Kurs anzeigen

Interaktive Übung

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

-- Pull events and golds by athlete_id for summer events
SELECT 
    ____,
    ____ AS total_events, 
    ____ AS gold_medals
FROM ____
GROUP BY ____
-- Order by total_events descending and athlete_id ascending
ORDER BY ____;
Code bearbeiten und ausführen