Recall & Review
beginner
What does the SUM function do in SQL?
The SUM function adds up all the values in a numeric column and returns the total.
Click to reveal answer
beginner
How do you use the SUM function to find the total sales from a 'sales' column in a table named 'orders'?
You write: <br>
SELECT SUM(sales) FROM orders;<br>This adds all values in the 'sales' column.Click to reveal answer
beginner
Can the SUM function be used with non-numeric columns?
No, SUM only works with numeric columns like integers or decimals. Using it on text columns causes an error.
Click to reveal answer
intermediate
What happens if the SUM function is used on an empty set of rows?
It returns NULL if there are no rows to sum. To get zero instead, you can use COALESCE, like
COALESCE(SUM(column), 0).Click to reveal answer
intermediate
How can you use SUM with GROUP BY to find total sales per customer?
Use: <br>
SELECT customer_id, SUM(sales) FROM orders GROUP BY customer_id;<br>This groups rows by customer and sums sales for each.Click to reveal answer
What does the SQL SUM function return?
✗ Incorrect
SUM adds all numeric values in a column and returns their total.
Which SQL clause is commonly used with SUM to group results?
✗ Incorrect
GROUP BY groups rows so SUM can calculate totals per group.
What will SUM(sales) return if there are no rows matching the query?
✗ Incorrect
SUM returns NULL when no rows are found.
Can SUM be used on a text column?
✗ Incorrect
SUM only works on numeric columns; using it on text causes an error.
How do you write a query to get total sales from 'orders' table?
✗ Incorrect
SUM(sales) adds all sales values to get the total.
Explain how the SUM function works in SQL and give an example query.
Think about adding numbers in a list.
You got /3 concepts.
Describe how to use SUM with GROUP BY to get totals per category.
Imagine adding sales per customer.
You got /3 concepts.