BigQuery - 查询执行期间超出资源:没有足够的资源用于查询计划 - 子查询太多

BigQuery - Resources exceeded during query execution: Not enough resources for query planning - too many subqueries

我正在尝试从

调整 table
ID DATE DATA
12345 2022-05-01 "Stringvalue.. rank:1"
12345 2022-05-01 "Stringvalue.. rank:2"
67890 2022-05-01 "Stringvalue.. rank:2"
67890 2022-05-01 "Stringvalue.. rank:2"

~

ID DATE DATA
12345 2022-05-01 "Stringvalue.. rank:23"
12345 2022-05-01 "Stringvalue.. rank:24"
67890 2022-05-01 "Stringvalue.. rank:23"
67890 2022-05-01 "Stringvalue.. rank:24"

ID DATE rank 1 rank 2 ... rank 24
12345 2022-05-01 "Stringvalue.. rank:1" "Stringvalue.. rank:2" "Stringvalue.. rank:23"
67890 2022-05-01 "Stringvalue.. rank:1" "Stringvalue.. rank:2" "Stringvalue.. rank:24"

参考这个:,我尝试通过

实现这个
SELECT DISTINCT ID, Date,
  (select ct.Data from cte ct where ct.ID= cte.ID and ct.Date = cte.Date and ct.rank =1) AS Ghour_1,
  (select ct.Data from cte ct where ct.ID = cte.ID and ct.Date= cte.Date and ct.rank =2) AS Ghour_2,
.
.
.

ct.Date = cte.Date and ct.rank =23) AS Ghour_23,
  (select ct.Data from cte ct where ct.ID = cte.ID and ct.Date = cte.Date and ct.rank =24) AS Ghour_24,
   from cte

但它抛出资源超出错误,这是因为我的子查询 select 语句太多了吗?谁能建议如何优化此查询?

以下面为起点

select * from (
  select *, replace(regexp_extract(data, r'\brank:(\d+)$'), ':', '') rank
  from your_table
)
pivot (any_value(data) as rank for rank in ('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24'))    

如果应用于您问题中的示例数据 - 输出为

以上内容很容易转换为动态枢轴 - 请参阅此处的多个示例 - 特别是至少我的一些回答专门针对此