0
0
SQLquery~5 mins

SUM function in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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
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
Which SQL clause is used with SUM() to get totals per category?
AGROUP BY
BWHERE
CORDER BY
DHAVING
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
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
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.