Aggregate

SUM

BigQueryBigQuery

Calculates the total sum of numeric values in a column. Supports multiple numeric types and is highly efficient for large-scale data analysis in BigQuery.

Tipe hasil: Same as input type (INT64, FLOAT64, NUMERIC, or BIGNUMERIC)Diperbarui: 13 Jun 2026

Syntax

SQL
SUM(expression) | SUM(DISTINCT expression)

Parameter

expressionnumericwajib

A numeric column or expression to sum (INT64, FLOAT64, NUMERIC, BIGNUMERIC)

DISTINCTmodifieropsional

Sums only unique values

Contoh Penggunaan

Sum Total Sales

SQL
1SELECT SUM(amount) as total_revenue
2FROM `project.dataset.transactions`
3WHERE DATE(transaction_date) = '2024-01-15';

Calculates total revenue for a specific date.

Hasil
125750000.00

SUM with GROUP BY

SQL
1SELECT
2 product_category,
3 SUM(quantity) as total_sold,
4 SUM(amount) as total_revenue
5FROM `project.dataset.sales`
6GROUP BY product_category
7ORDER BY total_revenue DESC;

Calculates total quantity sold and revenue per product category.

Hasil
product_categorytotal_soldtotal_revenue
Electronics5230087500000.00
Fashion12500031250000.00
Food & Beverage892006250000.00

Conditional SUM

SQL
1SELECT
2 SUM(amount) as total_sales,
3 SUM(IF(payment_method = 'credit_card', amount, 0)) as credit_card_sales,
4 SUM(IF(payment_method = 'bank_transfer', amount, 0)) as transfer_sales
5FROM `project.dataset.transactions`;

Calculates total and a breakdown by payment method in a single query.

Hasil
total_salescredit_card_salestransfer_sales
125000000.0085000000.0032500000.00

Running Total with Window Function

SQL
1SELECT
2 order_date,
3 amount,
4 SUM(amount) OVER (ORDER BY order_date) as running_total
5FROM `project.dataset.daily_sales`
6ORDER BY order_date;

Calculates a cumulative running total of daily sales.

Hasil
order_dateamountrunning_total
2024-01-0115000001500000
2024-01-0223000003800000
2024-01-0318000005600000

Pertanyaan Umum tentang SUM

Apa itu fungsi SUM di BigQuery?
Calculates the total sum of numeric values in a column. Supports multiple numeric types and is highly efficient for large-scale data analysis in BigQuery. Di BigQuery, fungsi SUM termasuk dalam kelompok fungsi yang sering digunakan untuk mengolah dan menganalisis data secara efisien.
Bagaimana cara menggunakan SUM di BigQuery?
Gunakan sintaks berikut: SUM(expression) | SUM(DISTINCT expression). Pastikan argumen yang dimasukkan sudah sesuai dengan tipe data yang diharapkan.
Apa nilai yang dikembalikan oleh fungsi SUM?
Fungsi SUM mengembalikan nilai bertipe Same as input type (INT64, FLOAT64, NUMERIC, or BIGNUMERIC). Pastikan tipe data hasil sudah sesuai dengan kebutuhan query atau formula kamu. Jika input mengandung nilai NULL, perilaku fungsi dapat berbeda — selalu periksa dokumentasi untuk memastikan hasilnya sesuai ekspektasi.
Apa saja parameter fungsi SUM?
Fungsi ini memiliki 1 parameter wajib dan 1 parameter opsional. Parameter yang digunakan: expression (numeric, wajib): A numeric column or expression to sum (INT64, FLOAT64, NUMERIC, BIGNUMERIC); DISTINCT (modifier, opsional): Sums only unique values.

Fungsi Terkait

Ngulik Langsung

Sudah paham SUM? Latih langsung di browser

Latihan interaktif, langsung di browser.

Latihan Langsung →