LoginSignup
0
0

Bigquery 備忘録2

Posted at

日付のついたテーブルを特定の条件で絞り込む

ex)過去4月1日時点のデータが欲しい場合

  SELECT
    table_id,
    SUBSTR(table_id, -8) as ymd
  FROM
    `table.__TABLES_SUMMARY__`
  WHERE
    table_id LIKE 'table_20%0401'
table_id ymd
table_20200401 20200401
table_20210401 20210401
table_20220401 20220401

上記をサブクエリ等にして再帰的にテーブルを検索する

with subquery as (
  SELECT
    table_id,
    SUBSTR(table_id, -8) as ymd
  FROM
    `table.__TABLES_SUMMARY__`
  WHERE
    table_id LIKE 'table_20%0401'
)  
select
   subquery.ymd,*
  FROM
    `table_*`,
    subquery
  WHERE
    _TABLE_SUFFIX = subquery.ymd
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0