Aggregate

APPROX_TOP_COUNT

BigQueryBigQuery

Returns the approximate most frequently occurring elements along with their counts. Uses a highly efficient approximate algorithm for large datasets.

Tipe hasil: ARRAY<STRUCT<value T, count INT64>>Diperbarui: 13 Jun 2026

Syntax

SQL
APPROX_TOP_COUNT(expression, number)

Parameter

expressionanywajib

The column or expression to find the top frequent values for

numberINT64wajib

The number of top values to return

Contoh Penggunaan

Top 5 Best-Selling Products

SQL
1SELECT
2 APPROX_TOP_COUNT(product_name, 5) as top_products
3FROM `project.dataset.orders`;

Finds the 5 products that are ordered most frequently.

Hasil
top_products
[{value: "iPhone 15", count: 15230},
{value: "MacBook Pro", count: 8450},
{value: "AirPods", count: 7890},
{value: "iPad", count: 6540},
... 1 baris lainnya

Top Search Keywords

SQL
1SELECT
2 top_keyword.value as keyword,
3 top_keyword.count as search_count
4FROM `project.dataset.search_logs`,
5UNNEST(APPROX_TOP_COUNT(search_query, 10)) as top_keyword;

Finds the 10 most popular search keywords.

Hasil
keywordsearch_count
gaming laptop125000
iphone 1598000
nike shoes87500
branded bag76000

Top Errors per Service

SQL
1SELECT
2 service_name,
3 APPROX_TOP_COUNT(error_code, 3) as top_errors
4FROM `project.dataset.error_logs`
5WHERE DATE(timestamp) = CURRENT_DATE()
6GROUP BY service_name;

Finds the 3 most frequent errors per service.

Hasil
service_nametop_errors
auth-service[{value: "AUTH_001", count: 5230}, ...]
api-gateway[{value: "TIMEOUT", count: 3450}, ...]

Pertanyaan Umum tentang APPROX_TOP_COUNT

Apa itu fungsi APPROX_TOP_COUNT di BigQuery?
Returns the approximate most frequently occurring elements along with their counts. Uses a highly efficient approximate algorithm for large datasets. Di BigQuery, fungsi APPROX_TOP_COUNT termasuk dalam kelompok fungsi yang sering digunakan untuk mengolah dan menganalisis data secara efisien.
Bagaimana cara menggunakan APPROX_TOP_COUNT di BigQuery?
Gunakan sintaks berikut: APPROX_TOP_COUNT(expression, number). Pastikan argumen yang dimasukkan sudah sesuai dengan tipe data yang diharapkan.
Apa nilai yang dikembalikan oleh fungsi APPROX_TOP_COUNT?
Fungsi APPROX_TOP_COUNT mengembalikan nilai bertipe ARRAY<STRUCT<value T, count 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 APPROX_TOP_COUNT?
Fungsi ini memiliki 2 parameter wajib. Parameter yang digunakan: expression (any, wajib): The column or expression to find the top frequent values for; number (INT64, wajib): The number of top values to return.
Ngulik Langsung

Sudah paham APPROX_TOP_COUNT? Latih langsung di browser

Latihan interaktif, langsung di browser.

Latihan Langsung →