Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does the SQL SUM() function do?
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 in a SQL query?
You write SELECT SUM(column_name) FROM table_name; to get the total of all values in that column.
Click to reveal answer
intermediate
Can SUM() be used with GROUP BY? What does it do then?
Yes, SUM() can be used with GROUP BY to add values for each group separately.
Click to reveal answer
intermediate
What happens if the column used in SUM() contains NULL values?
The SUM() function ignores NULL values and only adds the non-NULL numbers.
Click to reveal answer
beginner
Is it possible to use SUM() on non-numeric columns?
No, SUM() only works on numeric columns like integers or decimals.
Click to reveal answer
What does SELECT SUM(price) FROM sales; return?
AThe total of all prices in the sales table
BThe average price in the sales table
CThe number of rows in the sales table
DThe highest price in the sales table
✗ Incorrect
The SUM() function adds all values in the price column.
If a column has NULL values, how does SUM() treat them?
AIt treats NULL as zero
BIt returns NULL as the result
CIt ignores NULL values
DIt causes an error
✗ Incorrect
SUM() skips NULL values and sums only non-NULL numbers.
Which SQL clause is used with SUM() to get totals per category?
AGROUP BY
BWHERE
CORDER BY
DHAVING
✗ Incorrect
GROUP BY groups rows so SUM() totals each group.
Can you use SUM() on a text column?
AYes, it converts text to numbers automatically
BNo, it only works on numeric columns
CYes, but only if text contains numbers
DOnly in some SQL databases
✗ Incorrect
SUM() requires numeric data types to work.
What will this query return? SELECT SUM(quantity) FROM orders WHERE quantity > 5;
AMaximum quantity in orders
BSum of all quantities including those 5 or less
CCount of orders with quantity greater than 5
DSum of quantities greater than 5
✗ Incorrect
The WHERE clause filters rows before SUM() adds values.
Explain how the SUM() function works in SQL and give a simple example.
Think about adding numbers in a column.
You got /3 concepts.
Describe how you would use SUM() with GROUP BY to find totals per category.
Imagine adding sales per product type.
You got /3 concepts.
Practice
(1/5)
1. What does the SQL SUM() function do?
easy
A. Adds all numbers in a numeric column to get a total
B. Counts the number of rows in a table
C. Finds the highest value in a column
D. Deletes duplicate rows from a table
Solution
Step 1: Understand the purpose of SUM()
The SUM() function is designed to add up all values in a numeric column.
Step 2: Compare with other functions
Counting rows is done by COUNT(), highest value by MAX(), and deleting duplicates is unrelated.
Final Answer:
Adds all numbers in a numeric column to get a total -> Option A
Quick Check:
SUM() = total of numbers [OK]
Hint: SUM() always adds numbers in a column [OK]
Common Mistakes:
Confusing SUM() with COUNT()
Thinking SUM() works on text columns
Assuming SUM() deletes or filters rows
2. Which of the following is the correct syntax to get the total sales from a table named Orders with a column Amount?
easy
A. SELECT COUNT(Amount) FROM Orders;
B. SELECT SUM(Amount) FROM Orders;
C. SELECT TOTAL(Amount) FROM Orders;
D. SELECT ADD(Amount) FROM Orders;
Solution
Step 1: Identify the correct aggregate function
The function to add values is SUM(), so SUM(Amount) is correct.
Step 2: Check syntax correctness
SUM() is standard SQL; ADD() and TOTAL() are invalid, COUNT() counts rows, not sums.
Final Answer:
SELECT SUM(Amount) FROM Orders; -> Option B
Quick Check:
SUM() syntax correct [OK]
Hint: SUM() is the only valid function to add column values [OK]
Common Mistakes:
Using ADD() or TOTAL() which are not SQL functions
Using COUNT() instead of SUM()
Missing parentheses after SUM
3. Given the table Sales with rows: Product | Quantity Apple | 10 Banana | 5 Apple | 15 What is the result of the query: SELECT SUM(Quantity) FROM Sales WHERE Product = 'Apple';
medium
A. 10
B. 15
C. 25
D. 30
Solution
Step 1: Filter rows where Product = 'Apple'
Rows matching: Apple with Quantity 10 and Apple with Quantity 15.
Step 2: Sum the Quantity values for these rows
10 + 15 = 25.
Final Answer:
25 -> Option C
Quick Check:
10 + 15 = 25 [OK]
Hint: Sum only filtered rows matching condition [OK]
Common Mistakes:
Summing all rows ignoring WHERE clause
Adding only one matching row
Confusing Quantity values
4. Consider this query: SELECT SUM(Price) FROM Products WHERE Category = 'Electronics' It returns NULL instead of a number. What is the most likely cause?
medium
A. There are no rows with Category = 'Electronics'
B. The Price column contains text values
C. SUM() cannot be used with WHERE clause
D. The table Products does not exist
Solution
Step 1: Understand SUM() behavior with no matching rows
If no rows match the WHERE condition, SUM() returns NULL.
Step 2: Check other options
Price with text would cause error, SUM() works with WHERE, and table missing causes error, not NULL.
Final Answer:
There are no rows with Category = 'Electronics' -> Option A
Quick Check:
SUM() returns NULL if no rows match [OK]
Hint: SUM() returns NULL if no rows match WHERE [OK]
Common Mistakes:
Assuming SUM() returns 0 when no rows match
Thinking SUM() fails with WHERE clause
Ignoring NULL result meaning no data
5. You have a table Orders with columns CustomerID, OrderAmount. How do you write a query to find the total order amount for each customer?
hard
A. SELECT SUM(OrderAmount) FROM Orders GROUP BY CustomerID;
B. SELECT CustomerID, SUM(OrderAmount) FROM Orders;
C. SELECT CustomerID, TOTAL(OrderAmount) FROM Orders GROUP BY CustomerID;
D. SELECT CustomerID, SUM(OrderAmount) FROM Orders GROUP BY CustomerID;
Solution
Step 1: Use GROUP BY to group rows by CustomerID
This groups all orders per customer so we can sum their amounts.
Step 2: Use SUM(OrderAmount) to add orders per group
SUM() calculates total order amount for each customer group.
Final Answer:
SELECT CustomerID, SUM(OrderAmount) FROM Orders GROUP BY CustomerID; -> Option D
Quick Check:
GROUP BY + SUM() = total per group [OK]
Hint: Use GROUP BY with SUM() to total per group [OK]