簡體   English   中英

在 bigquery 中按每個組查找前 100 個值

[英]find top 100 values by each group in bigquery

嗨,我有這樣的數據(表名:topcount)

    ID     Value       Count_total
    1      Sam         3008
    1      Sarah       5677
    3      Gil         3455
    2      Gil         4555
...

我想找到每個 ID 的前 100 個值的計數。

到目前為止我已經嘗試過了-

 with top1000 as (select ID, ARRAY_AGG(STRUCT(count_total) ORDER BY count_total DESC LIMIT 1000) as top from topcount group by app_id) select app_id, sum(top.count_total) from top1000

我如何有效地寫這個?

考慮以下方法

select * from your_table
qualify row_number() over(partition by ID order by Count_total desc) <= 100   

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM