Query editor
WITH balance_buckets AS (SELECT bucket_name, bucket_orderFROM (VALUES('$1k-$5k', 1),('$5k-$25k', 2),('$25k-$100k', 3),('$100k-$250k', 4)) AS t(bucket_name, bucket_order)),-- 'all' is a selection option, not an actual chain name, so it's removed from here.actual_chain AS (SELECT chain_nameFROM (VALUES ('base'), ('ethereum')) AS t(chain_name)),-- Pre-filter the chain on the user's multiselect selection.-- This handles 'all' as a special selection that implies all actual chains.filtered_chain AS (SELECT chain_nameFROM actual_chainWHERE-- If 'all' is one of the selected options from the multiselect list,-- then include all actual chains from actual_chain.'all' IN ('{{chain}}')OR-- Otherwise, include only the specific actual chains that were selected.chain_name IN ('{{chain}}')),-- Combine the data from your two materialized views.combined_wallets AS (SELECTwallet,portfolio_value_usd,'base' AS blockchainFROM dune.web3cryptotech.result_main_baseUNION ALLSELECTwallet,portfolio_value_usd,'ethereum' AS blockchainFROM dune.web3cryptotech.result_main_ethereum),-- Assign each wallet to a value bucket.wallets_with_buckets AS (SELECTblockchain,wallet,portfolio_value_usd,CASEWHEN portfolio_value_usd >= 1000 AND portfolio_value_usd < 5000 THEN '$1k-$5k'WHEN portfolio_value_usd >= 5000 AND portfolio_value_usd < 25000 THEN '$5k-$25k'WHEN portfolio_value_usd >= 25000 AND portfolio_value_usd < 100000 THEN '$25k-$100k'WHEN portfolio_value_usd >= 100000 AND portfolio_value_usd <= 250000 THEN '$100k-$250k'END AS value_bucketFROM combined_wallets