Aggregate

COUNT

BigQueryBigQuery

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 2026

Syntax

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
1SELECT COUNT(*)
2FROM `project.dataset.orders`;

Counts the total number of rows in the orders table.

Hasil
2547831

Count Non-NULL Values

SQL
1SELECT COUNT(email)
2FROM `project.dataset.users`;

Counts how many users have an email address (non-NULL).

Hasil
2340000

Count Distinct Values

SQL
1SELECT COUNT(DISTINCT customer_id)
2FROM `project.dataset.transactions`;

Counts how many unique customers have made a transaction.

Hasil
125000

COUNT with GROUP BY

SQL
1SELECT
2 region,
3 COUNT(*) as total_orders,
4 COUNT(DISTINCT product_id) as unique_products
5FROM `project.dataset.sales`
6GROUP BY region
7ORDER BY total_orders DESC;

Counts total orders and unique products per region.

Hasil
regiontotal_ordersunique_products
Jakarta5234501245
Surabaya312200892
Bandung245000756

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.

Fungsi Terkait

Ngulik Langsung

Sudah paham COUNT? Latih langsung di browser

Latihan interaktif, langsung di browser.

Latihan Langsung →