Introduction
The SUM function adds up all the numbers in a column to give you the total. It helps you quickly find the total amount or quantity.
Jump into concepts and practice - no test required
SELECT SUM(column_name) FROM table_name;
SELECT SUM(price) FROM products;
SELECT SUM(quantity) FROM orders WHERE status = 'completed';
SELECT category, SUM(sales) FROM sales_data GROUP BY category;
CREATE TABLE sales ( id INT, product VARCHAR(50), amount INT ); INSERT INTO sales (id, product, amount) VALUES (1, 'Apple', 10), (2, 'Banana', 15), (3, 'Apple', 5), (4, 'Orange', 20); SELECT SUM(amount) FROM sales;
SUM() function do?Orders with a column Amount?Sales with rows:Product | Quantity
Apple | 10
Banana | 5
Apple | 15SELECT SUM(Quantity) FROM Sales WHERE Product = 'Apple';SELECT SUM(Price) FROM Products WHERE Category = 'Electronics'Orders with columns CustomerID, OrderAmount. How do you write a query to find the total order amount for each customer?