0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

BigQuery Tips 日付を取得するUDF

Last updated at Posted at 2024-11-12

SQLを書いて日付範囲を変更して確認していきたい時に、日付変更箇所が複数ある場合UDFを使うと楽になる。
tempをつけるとその名の通り一時的に関数が作成される。

create temp function start_date() as (TIMESTAMP('2024-01-01 00:00:00'));
create temp function end_date() as (TIMESTAMP('2021-01-02 23:59:59'));

with item_master as (
    select
        item_id
        ,category
        ,create_date
    from 
        item_master
    where 
        create_date between start_date() and end_date() 
)

select 
    tran.item_id 
    ,item_master.category
    ,tran.price
    ,tran.create_date
from 
    tran
        left outer join 
    item_master
        on tran.item_id = item_master.item_id
where 
    create_date between start_date() and end_date() 

※SQLは適当です

ちなみにtempをtemporaryと書いても問題ない。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?