This is my code:
with Swapping as ( SELECT tx_id, 'swap' as type, swapper from solana.core.fact_swaps where SWAP_FROM_MINT ='5h6ssFpeDeRbzsEHDbTQNH7nVGgsKrZydxdSTnLm6QdV' and SUCCEEDED = 'TRUE' and BLOCK_TIMESTAMP >='2022-07-01' ), Transfering as ( SELECT tx_id, 'Transfer' as type, tx_From from solana.core.fact_transfers where mint ='5h6ssFpeDeRbzsEHDbTQNH7nVGgsKrZydxdSTnLm6QdV' and BLOCK_TIMESTAMP >='2022-07-01' ), Supply as ( select tx_id, 'Supply' as type, signers[0] as supplier from solana.core.fact_events join solana.core.fact_transactions using (tx_id) where succeeded = 'TRUE' and program_id = 'So1endDq2YkqhipRh3WViPa8hdiSpxWy6z3Z6tMCpAo' and instruction:accounts[2] = '8PbodeaosQP19SjYFx855UMqWxH2HynZLdBXmsrbac36' and instruction:accounts[3] = '8UviNr47S8eL6J3WfDxMRa3hvLta1VDJwNWqsDgtN3Cv' and instruction:accounts[4] ='5h6ssFpeDeRbzsEHDbTQNH7nVGgsKrZydxdSTnLm6QdV' and BLOCK_TIMESTAMP >='2022-07-01' ), holder as ( select tx_id, 'holder' as type from solana.core.fact_events join solana.core.fact_transactions using (tx_id) where program_id = 'So1endDq2YkqhipRh3WViPa8hdiSpxWy6z3Z6tMCpAo' and inner_instruction:instructions[1]:parsed:info:mint ='5h6ssFpeDeRbzsEHDbTQNH7nVGgsKrZydxdSTnLm6QdV' and succeeded = 'TRUE' and signers[0] not in (select swapper from Swapping) and signers[0] not in (select tx_From from Transfering) and signers[0] not in (select supplier from Supply) and BLOCK_TIMESTAMP >='2022-07-01' ), main1 as ( SELECT tx_id, type from Swapping union ALL SELECT tx_id, type from Transfering union ALL SELECT tx_id, type from Supply union ALL SELECT tx_id, type from holder ), T1 as ( select BLOCK_TIMESTAMP::date as date, INNER_INSTRUCTION:instructions[1]:parsed:info:mint as token, (INNER_INSTRUCTION:instructions[1]:parsed:info:amount)/pow(10,9) as amounts, tx_id from solana.core.fact_events join solana.core.fact_transactions using (tx_id) where tx_id in (select tx_id from main1) and BLOCK_TIMESTAMP >='2022-07-01' ) select case when a.amounts < '1' then 'less than 1' when a.amounts >= '1' and a.amounts <'5' then 'Between 1 and 5' when a.amounts >= '5' and a.amounts <'10' then 'Between 5 and 10' when a.amounts >= '10' and a.amounts <'50' then 'Between 10 and 50' when a.amounts >= '50' then 'More than 50' End as amounts, b.type, count(b.tx_id) from T1 a join main1 b where date >='2022-07-01' and amounts is not null group by 1,2