我有一个查询:
select A.*, A.DocumentID.DocId, D.Key, D.Value
from `moonoia-bpo-run.dam.events` A
left join unnest (A.metadata) D
where A.Creationtimestamp > '2018-10-01'
order by Creationtimestamp desc
limit 10000
我想将每天的值限制为10000。我该怎么办?
答案 0 :(得分:2)
您可以使用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 `moonoia-bpo-run.dam.events` e left join
unnest (A.metadata) D
where A.Creationtimestamp > '2018-10-01'
) e
where seqnum <= 1000
order by Creationtimestamp desc