Skip to content

Instantly share code, notes, and snippets.

@sh16ma
Last active March 1, 2023 06:01
Show Gist options
  • Save sh16ma/39899cdb4cff7a91ce3be7d11cd524cf to your computer and use it in GitHub Desktop.
Save sh16ma/39899cdb4cff7a91ce3be7d11cd524cf to your computer and use it in GitHub Desktop.
#πŸ”Ž #BigQuery #BigQueryScripting #_TABLE_SUFFIX #ga_data
#standaardSQL
# ι›†θ¨ˆζœŸι–“
decleare term_start string default '2020-01-01';
decleare term_end string default '2020-12-31';
decleare prep_table_suffix string;
set prep_table_suffix = (
select format_date('%Y%m%d', current_date('Asia/Tokyo')) as TODAY
);
with
rsv_raw as (
select * from `pj.ds.hoge_reservation_*` where _TABLE_SUFFIX = prep_table_suffix
)
,rsv_prep as (
# 前処理テーブル
select
SHOPOWNER_ID
, RSV_DATE
, date_trunc(RSV_DATE, day) as RSV_DATE_TRUNC
, APPOINT_DATETIME
, RSV_VALID
, LOG_NO
, MENU_ID
from
rsv_raw
where
RSV_VALID = '1' --ζœ‰εŠΉδΊˆη΄„
)
, info_raw as (
select 1
)
, info_prep as (
select 1
)
, ga_raw as (
select 1
)
, ga_prep as (
select 1
)
, output as (
select
MENU-ID
, count(distinct LOG_NO) as CV
from
rsv_prep
where
RSV_DATE_TRUNC between datetime(term_start) and datetime(term_end)
)
select * from output
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment