GCP BigQuery -SQL 最佳实践

1. 使用 with 语句写多个SQL语句

2. 使用 begin with 语句写多个SQL语句

3. 提取某daily history表中最新的 image date的数据,进行计算

使用declare 函数进行声明后,在 where 语句中用 unnest 函数

declare max_image_dt array<date>;

set max_image_dt = array(SELECT
Max(IMAGE_DT)
FROM
`usecase.datasets.table_DH` where image_dt > (current_date()-10)
)
;

select id
,accountNumber
,balance
,image_dt
from `usecase.datasets.table_DH`
where image_dt in unnest(max_image_dt)

4. 使用开窗函数 row_number 去重

posted @ 2021-10-09 22:06  Leo叶  阅读(368)  评论(0)    收藏  举报