Query editor
-- All Time: ever-KR as of report-day close. Latest-day Headline: latest country at that same cutoff is KR.WITH historical AS (SELECT max(new_users) FILTER(WHERE granularity='all_time') total_users,max(trading_users) FILTER(WHERE granularity='all_time') total_trading_users,max(trading_volume_usd) FILTER(WHERE granularity='all_time') total_trading_volume_usd,max(tokens_launched) FILTER(WHERE granularity='all_time') total_tokens_launched,max(token_trading_volume_usd) FILTER(WHERE granularity='all_time') total_token_trading_volume_usd,max(as_of_day) as_of_day,max(cutoff_utc) cutoff_utc,min(first_kr_observed) first_kr_observedFROM query_9160104), today AS (SELECT trading_users today_trading_users,trading_volume_usd today_trading_volume_usd,tokens_launched today_tokens_launched,token_trading_volume_usd today_token_trading_volume_usd,unpriced_trader_events,unpriced_token_events,as_of_dayFROM query_9160369 WHERE granularity='daily' AND cast(period AS date)=as_of_day), latest_cohort AS (-- Latest country as of the report-day close; used by latest-day Headline.-- Login events use create_date. ingested_at is only a deterministic tie-breaker.WITH report AS (SELECT max(cast(at_timezone(create_date,'Asia/Seoul') AS date)) as_of_dayFROM dune.fourmeme.dataset_data_meme_login_recordWHERE create_date < with_timezone(cast(cast(at_timezone(current_timestamp,'Asia/Seoul') AS date) AS timestamp),'Asia/Seoul')), closed_logins AS (SELECT lower(trim(user_address)) wallet,create_date,ingested_at,id,upper(trim(country_code)) country,as_of_dayFROM dune.fourmeme.dataset_data_meme_login_record CROSS JOIN reportWHERE cast(at_timezone(create_date,'Asia/Seoul') AS date)<=as_of_dayAND regexp_like(lower(trim(user_address)),'^0x[0-9a-f]{40}$')AND lower(trim(user_address))<>'0x0000000000000000000000000000000000000000'), ranked AS (SELECT *,row_number() OVER(PARTITION BY wallet ORDER BY create_date DESC,ingested_at DESC,id DESC) rn,min(create_date) OVER(PARTITION BY wallet) first_seen,min(CASE WHEN country='KR' THEN create_date END) OVER(PARTITION BY wallet) first_kr_loginFROM closed_logins)SELECT from_hex(substr(wallet,3)) wallet,first_kr_login,create_date last_kr_login,first_seen,create_date latest_login,as_of_day,cast(at_timezone(first_kr_login,'Asia/Seoul') AS date) first_kr_day,cast(at_timezone(with_timezone(cast(as_of_day + interval '1' day AS timestamp),'Asia/Seoul'),'UTC') AS timestamp) cutoff_utcFROM ranked WHERE rn=1 AND country='KR'), logins AS (SELECT as_of_day,count(*) latest_kr_wallets,count_if(cast(at_timezone(first_seen,'Asia/Seoul') AS date)=as_of_day) today_new_users,count_if(cast(at_timezone(latest_login,'Asia/Seoul') AS date)=as_of_day) today_active_usersFROM latest_cohort GROUP BY 1)SELECT h.*,t.today_trading_users,t.today_trading_volume_usd,t.today_tokens_launched,t.today_token_trading_volume_usd,t.unpriced_trader_events,t.unpriced_token_events,l.latest_kr_wallets,l.today_new_users,l.today_active_users,current_timestamp extracted_atFROM historical h JOIN today t ON h.as_of_day=t.as_of_day JOIN logins l ON h.as_of_day=l.as_of_day