Aggregate
BigQuery
SUM
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 2026Syntax
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
1 SELECT SUM(amount) as total_revenue 2 FROM `project.dataset.transactions` 3 WHERE DATE(transaction_date) = '2024-01-15';
Calculates total revenue for a specific date.
Hasil
125750000.00
SUM with GROUP BY
SQL
1 SELECT 2 product_category, 3 SUM(quantity) as total_sold, 4 SUM(amount) as total_revenue 5 FROM `project.dataset.sales` 6 GROUP BY product_category 7 ORDER BY total_revenue DESC;
Calculates total quantity sold and revenue per product category.
Hasil
| product_category | total_sold | total_revenue |
|---|---|---|
| Electronics | 52300 | 87500000.00 |
| Fashion | 125000 | 31250000.00 |
| Food & Beverage | 89200 | 6250000.00 |
Conditional SUM
SQL
1 SELECT 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 5 FROM `project.dataset.transactions`;
Calculates total and a breakdown by payment method in a single query.
Hasil
| total_sales | credit_card_sales | transfer_sales |
|---|---|---|
| 125000000.00 | 85000000.00 | 32500000.00 |
Running Total with Window Function
SQL
1 SELECT 2 order_date, 3 amount, 4 SUM(amount) OVER (ORDER BY order_date) as running_total 5 FROM `project.dataset.daily_sales` 6 ORDER BY order_date;
Calculates a cumulative running total of daily sales.
Hasil
| order_date | amount | running_total |
|---|---|---|
| 2024-01-01 | 1500000 | 1500000 |
| 2024-01-02 | 2300000 | 3800000 |
| 2024-01-03 | 1800000 | 5600000 |
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.
Ngulik Langsung
Latihan Langsung →Sudah paham SUM? Latih langsung di browser
Latihan interaktif, langsung di browser.