![](/img/trans.png)
[英]BigQuery - how to change the order of the schema with nested columns when creating a view?
[英]BigQuery how to order a nested and repeated column?
我有一个包含特定动物发生的事件的表格,例如购买、死亡、出生等。许多事件发生在不同的日期,但有些事件发生在同一日期(格式 yyyy-mm-dd)。 对于同一天发生的事件,有“event_id”一栏进行分类。 我的问题是:如何创建一个查询,为每个现有动物返回一个嵌套和重复的列,其中所有事件按日期 + ID 排序?
select animal,
array_agg(struct(event_id, event_date, event_name, event_etc, ...)) as event
from events
group by animal;
ARRAY_AGG
支持ORDER BY
( ref )。 所以,你可以这样做:
SELECT
animal,
ARRAY_AGG(
STRUCT(
event_id,
event_date,
event_name,
...
) ORDER BY event_date, event_id
) AS events
FROM events
GROUP BY animal;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.