SUM (Lakehouse v1)
Aggregate function.
The SUM() function calculates the sum of a set of values.
Analyze Syntax
Section titled “Analyze Syntax”func.sum(<column>)Analyze Examples
Section titled “Analyze Examples”func.sum(table.quantity).alias('total_quantity_sold')
| total_quantity_sold ||---------------------|| 41 |SQL Syntax
Section titled “SQL Syntax”SUM(<expr>)Arguments
Section titled “Arguments”| Arguments | Description |
|---|---|
<expr> | Any numerical expression |
Return Type
Section titled “Return Type”A double if the input type is double, otherwise integer.
SQL Examples
Section titled “SQL Examples”Create a Table and Insert Sample Data
CREATE TABLE sales_data ( id INT, product_id INT, quantity INT);
INSERT INTO sales_data (id, product_id, quantity)VALUES (1, 1, 10), (2, 2, 5), (3, 3, 8), (4, 4, 3), (5, 5, 15);Query Demo: Calculate the Total Quantity of Products Sold
SELECT SUM(quantity) AS total_quantity_soldFROM sales_data;Result
| total_quantity_sold ||---------------------|| 41 |