Aggregate
BigQuery
COUNT
Counts the number of rows or non-NULL values in a column. A fundamental aggregate function in BigQuery for large-scale data analysis.
Tipe hasil:
INT64Diperbarui: 13 Jun 2026Syntax
SQL
COUNT(*) | COUNT(expression) | COUNT(DISTINCT expression)Parameter
*specialopsional
Counts all rows including NULLs
expressionanyopsional
A column or expression. Only non-NULL values are counted
DISTINCTmodifieropsional
Counts only unique (non-duplicate) values
Contoh Penggunaan
Count Total Rows
SQL
1 SELECT COUNT(*) 2 FROM `project.dataset.orders`;
Counts the total number of rows in the orders table.
Hasil
2547831
Count Non-NULL Values
SQL
1 SELECT COUNT(email) 2 FROM `project.dataset.users`;
Counts how many users have an email address (non-NULL).
Hasil
2340000
Count Distinct Values
SQL
1 SELECT COUNT(DISTINCT customer_id) 2 FROM `project.dataset.transactions`;
Counts how many unique customers have made a transaction.
Hasil
125000
COUNT with GROUP BY
SQL
1 SELECT 2 region, 3 COUNT(*) as total_orders, 4 COUNT(DISTINCT product_id) as unique_products 5 FROM `project.dataset.sales` 6 GROUP BY region 7 ORDER BY total_orders DESC;
Counts total orders and unique products per region.
Hasil
| region | total_orders | unique_products |
|---|---|---|
| Jakarta | 523450 | 1245 |
| Surabaya | 312200 | 892 |
| Bandung | 245000 | 756 |
Pertanyaan Umum tentang COUNT
Apa itu fungsi COUNT di BigQuery?
Counts the number of rows or non-NULL values in a column. A fundamental aggregate function in BigQuery for large-scale data analysis. Di BigQuery, fungsi COUNT termasuk dalam kelompok fungsi yang sering digunakan untuk mengolah dan menganalisis data secara efisien.
Bagaimana cara menggunakan COUNT di BigQuery?
Gunakan sintaks berikut: COUNT(*) | COUNT(expression) | COUNT(DISTINCT expression). Pastikan argumen yang dimasukkan sudah sesuai dengan tipe data yang diharapkan.
Apa nilai yang dikembalikan oleh fungsi COUNT?
Fungsi COUNT mengembalikan nilai bertipe INT64. 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 COUNT?
Semua 3 parameter bersifat opsional. Parameter yang digunakan: * (special, opsional): Counts all rows including NULLs; expression (any, opsional): A column or expression. Only non-NULL values are counted; DISTINCT (modifier, opsional): Counts only unique (non-duplicate) values.
Ngulik Langsung
Latihan Langsung →Sudah paham COUNT? Latih langsung di browser
Latihan interaktif, langsung di browser.