Returns the approximate elements with the highest total weight. Similar to APPROX_TOP_COUNT but ranked by sum of weights rather than count.
ARRAY<STRUCT<value T, sum INT64>>Diperbarui: 13 Jun 2026APPROX_TOP_SUM(expression, weight, number)The column or expression to group by
The weight value to be summed per group
The number of top values to return
1 SELECT 2 APPROX_TOP_SUM(product_name, revenue, 5) as top_by_revenue 3 FROM `project.dataset.sales`;
Finds the 5 products with the highest total revenue.
| top_by_revenue |
|---|
| [{value: "MacBook Pro", sum: 8750000000}, |
| {value: "iPhone 15", sum: 6520000000}, |
| {value: "iPad Pro", sum: 3450000000}, |
| {value: "iMac", sum: 2890000000}, |
| ... 1 baris lainnya |
1 SELECT 2 top_customer.value as customer_id, 3 top_customer.sum as total_spending 4 FROM `project.dataset.transactions`, 5 UNNEST(APPROX_TOP_SUM(customer_id, amount, 10)) as top_customer;
Finds the 10 customers with the highest total spending.
| customer_id | total_spending |
|---|---|
| C001234 | 125000000 |
| C005678 | 98500000 |
| C002345 | 87250000 |
1 SELECT 2 region, 3 APPROX_TOP_SUM(category, quantity_sold, 3) as top_categories 4 FROM `project.dataset.regional_sales` 5 GROUP BY region;
Top 3 categories by quantity per region.
| region | top_categories |
|---|---|
| Jakarta | [{value: "Electronics", sum: 52000}, ...] |
| Surabaya | [{value: "Fashion", sum: 48000}, ...] |
Sudah paham APPROX_TOP_SUM? Latih langsung di browser
Latihan interaktif, langsung di browser.