Query editor
with iv_sales as (select tier,count(1) as tx_cnt,coalesce(sum(amount),0) as tot_sold_amt,coalesce(sum(case when rnd = 'WL' then amount end),0) as wl_sold_amt,coalesce(sum(case when rnd = 'PUBLIC' then amount end),0) as public_sold_amt,count(distinct buyer) as unique_buyer,sum(usd_price) as tot_sold_usd,sum(case when rnd = 'WL' and currency = 'WETH' then price end) as wl_sold_eth,sum(case when rnd = 'WL' and currency = 'USDC' then price end) as wl_sold_usdc,sum(case when rnd = 'PUBLIC' and currency = 'WETH' then price end) as public_sold_ethfrom query_3751770group by 1)select a.tier,a.usdc_price,a.eth_price,a.tot_cnt,coalesce(b.tot_sold_amt,0) as tot_sold_amt,a.tot_cnt - coalesce(b.tot_sold_amt,0) as tot_remain_amt,coalesce(b.tot_sold_amt,0) / a.tot_cnt as tot_sold_pct-- ,a.wl_cnt,coalesce(b.wl_sold_amt,0) as wl_sold_amt-- ,a.wl_cnt - coalesce(b.wl_sold_amt,0) as wl_remain_amt-- ,case when a.wl_cnt > 0 then coalesce(b.wl_sold_amt,0) / a.wl_cnt else 0 end as wl_sold_pct,a.public_cnt,coalesce(b.public_sold_amt,0) as public_sold_amt,a.public_cnt - coalesce(b.public_sold_amt,0) as public_remain_amt,case when a.public_cnt > 0 then coalesce(b.public_sold_amt,0) / a.public_cnt else 0 end as public_sold_pct-- ,a.eth_price * a.tot_cnt as list_eth_amt,coalesce(b.tot_sold_usd,0) as tot_sold_usd,coalesce(b.wl_sold_eth,0) as wl_sold_eth-- ,case when a.tot_cnt > 0 then coalesce(b.tot_sold_eth,0) / (a.eth_price * a.tot_cnt) else 0 end as tot_eth_pct,coalesce(b.wl_sold_usdc,0) as wl_sold_usdc-- ,case when a.wl_cnt > 0 then coalesce(b.wl_sold_eth,0) / (a.eth_price * a.wl_cnt) else 0 end as wl_eth_pct,coalesce(b.public_sold_eth,0) as public_sold_eth-- ,case when a.public_cnt > 0 then coalesce(b.public_sold_eth,0) / (a.eth_price * a.public_cnt) else 0 end as public_eth_pctfrom query_3793282 aleft join iv_sales b on b.tier = a.tierorder by 1