Sql 如何将每天的值限制为1000

Sql 如何将每天的值限制为1000,sql,google-bigquery,tableau-api,greatest-n-per-group,Sql,Google Bigquery,Tableau Api,Greatest N Per Group,我有一个疑问: 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。如何操作?您可以使用行编号来枚举行: select *

我有一个疑问:

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。如何操作?

您可以使用行编号来枚举行:

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 
可能重复的