Content
SUM calculates the total of a numeric column. Perfect for financial reports and data analysis.
Basic SUM Syntax
SELECT SUM(column) FROM table;
Sum All Values
SELECT SUM(amount) as total_revenue FROM orders;
Sum with Condition
SELECT SUM(amount) FROM orders WHERE status = 'completed';
Sum with GROUP BY
SELECT category, SUM(sales) as total_sales
FROM products
GROUP BY category;
Sum Multiple Columns
SELECT
SUM(quantity) as total_items,
SUM(price * quantity) as total_value
FROM order_items;
Sum with Date Range
SELECT SUM(amount) FROM orders
WHERE order_date BETWEEN '2025-01-01' AND '2025-12-31';
Generate SUM Queries
Ask for totals in plain English and AI2sql creates the query.


