Query editor
with position_open as (select *, cast(json_query(position, 'lax $.initMargin') as uint256) as init_margin,cast(json_query(position, 'lax $.extraMargin') as uint256) as extra_margin,cast(json_query(position, 'lax $.leverage') as uint256) as leverage,json_value(position, 'lax $.owner') as owner,case when json_value(position, 'lax $.tradingPairId') = '0x9317fdc1187cd642023ce08ab1c6f9b51f60ee9677f05deb46f6080e26c55a14' then 'BTCUSD'when json_value(position, 'lax $.tradingPairId') = '0xd02ccd288a82d94573c88f153f9918f57695561788490de870e021d484c73bbf' then 'ETHUSD'else 'BNBUSD' end as trading_pair,cast(json_query(position, 'lax $.initMargin') as uint256) * cast(json_query(position, 'lax $.leverage') as uint256) / pow(10, 18) as open_volume_busdfrom borabora_bnb.Pool_evt_OpenPosition), position_close as (select c.*,cast(json_value(closeInfo, 'lax $.positionId') as uint256) as positionId,(o.init_margin + o.extra_margin) * o.leverage / pow(10, 18) as close_volume_busd,o.owner, o.trading_pair,json_value(closeInfo, 'lax $.isProfit') as isProfit,cast(json_query(closeInfo, 'lax $.pnl') as uint256) as pnlfrom borabora_bnb.Pool_evt_ClosePosition c left join position_open o on cast(json_value(c.closeInfo, 'lax $.positionId') as uint256) = o.positionId), uni as (select evt_block_time, open_volume_busd as volume, trading_pair, positionId, 'open' as "type", owner from position_openunion allselect evt_block_time, close_volume_busd as volume, trading_pair, positionId, 'close' as "type", owner from position_close), daily_users as (select distinct date_trunc('day', evt_block_time) as dt, ownerfrom uni), new_user_dt as (select owner, min(dt) as new_user_dtfrom daily_usersgroup by owner), daily_users_by_type as (select u.*,case when u.dt = d.new_user_dt then 'NEW USER'ELSE 'RETURNING USER' end as user_typefrom daily_users u left join new_user_dt d on u.owner = d.owner order by u.dt), daily_users_cnt_by_type as (select dt,count(*) filter(where user_type = 'NEW USER') as new_user_cnt,count(*) filter(where user_type = 'RETURNING USER') as returning_user_cntfrom daily_users_by_typegroup by dt)select dt,new_user_cnt as "New Users",returning_user_cnt as "Returning Users",sum(new_user_cnt) over(order by dt rows between unbounded preceding and current row) + 829 as "Cumulative Unique Users"from daily_users_cnt_by_type