Query editor
with ref as (select distinct blockchain, lower(token_id) tid, coalesce(transfer_restriction,'unknown') tr, coalesce(asset_type,'unknown') atype, product_id from rwa_multichain.tokens_reference_data),d as (select max(day) mx from rwa_multichain.supply where day >= current_date - interval '7' day),b as (select s.day, case when r.atype='fund_unit' then 'fund_unit' else 'other' end grp, r.tr, r.product_id, s.supply_usd usdfrom rwa_multichain.supply s join ref r on r.blockchain=s.blockchain and r.tid=lower(s.token_address) cross join dwhere s.day in (d.mx, d.mx - interval '365' day))select day, coalesce(grp,'ALL') grp, coalesce(tr,'ALL') tr, count(distinct product_id) products, sum(usd) usdfrom b group by grouping sets ((day, grp, tr), (day, tr), (day, grp), (day))order by day, grp, usd desc