SQL - Aggregate FunctionsWhich SQL expression correctly replaces NULL values with zero before summing a column sales?ASUM(NULLIF(sales, 0))BSUM(sales)CSUM(COALESCE(sales, 0))DSUM(ISNULL(sales))Check Answer
Step-by-Step SolutionSolution:Step 1: Understand COALESCE usageCOALESCE(sales, 0) replaces NULL values in sales with 0 before summing.Step 2: Check other optionsSUM(sales) ignores NULLs, NULLIF returns NULL if sales=0, ISNULL(sales) is incomplete syntax.Final Answer:SUM(COALESCE(sales, 0)) -> Option CQuick Check:Use COALESCE to replace NULLs before aggregation [OK]Quick Trick: Use COALESCE(column, 0) to treat NULL as zero in sums [OK]Common Mistakes:MISTAKESUsing SUM(sales) and expecting NULLs counted as zeroConfusing NULLIF with COALESCEUsing ISNULL without second argument
Master "Aggregate Functions" in SQL9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More SQL Quizzes GROUP BY and HAVING - GROUP BY with NULL values behavior - Quiz 4medium INNER JOIN - Joining on primary key to foreign key - Quiz 3easy INNER JOIN - Self join concept - Quiz 7medium LEFT and RIGHT JOIN - Why outer joins are needed - Quiz 7medium Subqueries - Subquery with EXISTS operator - Quiz 5medium Subqueries - Why subqueries are needed - Quiz 1easy Table Constraints - Constraint naming conventions - Quiz 9hard Table Relationships - ER diagram to table mapping - Quiz 8hard Table Relationships - One-to-one relationship design - Quiz 13medium Views - Dropping and altering views - Quiz 14medium