【问题标题】:How can limit the values per day to 1000如何将每天的值限制为 1000
【发布时间】:2019-10-16 14:43:54
【问题描述】:

我有疑问:

select A.*, A.DocumentID.DocId, D.Key, D.Value
from `serv.dam.events` A  
left join unnest (A.metadata) D 
where A.Creationtimestamp > '2018-10-01' 
order by Creationtimestamp desc 
limit 10000

我想将每天的值限制为 10000。我该怎么做?

【问题讨论】:

标签: sql google-bigquery tableau-api greatest-n-per-group


【解决方案1】:

您可以使用row_number() 来枚举行:

select *
from (select e.*, e.DocumentID.DocId, D.Key, D.Value,
             row_number() over (partition by date(a.creationtimestamp) order by rand()) as seqnum
      from `serv.dam.events` e left join
           unnest (A.metadata) D 
      where A.Creationtimestamp > '2018-10-01' 
     ) e
where seqnum <= 1000
order by Creationtimestamp desc 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-18
    • 1970-01-01
    • 2012-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-31
    • 1970-01-01
    相关资源
    最近更新 更多