BigQuery filter per the last Date and use Partition

后端 未结 3 1147
清酒与你
清酒与你 2021-01-27 03:27

I asked how to filter the last date and got excellent answers (BigQuery, how to use alias in where clause?), they all work, but, they scan the whole table, the field SETTLEMENT

3条回答
  •  时光说笑
    2021-01-27 04:01

    Assuming SETTLEMENTDATE is of DATE data type, you can use below to get today's partition

    SELECT *
    FROM `biengine-252003.aemo2.daily`
    WHERE SETTLEMENTDATE = CURRENT_DATE()     
    

    or, for example for yesterday's partition

    SELECT *
    FROM `biengine-252003.aemo2.daily`
    WHERE SETTLEMENTDATE = DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY)     
    

    See more at https://cloud.google.com/bigquery/docs/querying-partitioned-tables#querying_partitioned_tables_2

提交回复
热议问题