with token_plan as (select token_name, hook_amount from (values ('Token Type','BEP-20 on BNB Chain'), ('Total Token Supply','500,000,000 HOOK'), ('Private Sale Allocation','100,000,000 HOOK'), ('Private Sale Token Price','0.06 USD to 0.12 USD / HOOK'), ('Private Sale Amount Raised','~ 6,000,000 USD'), ('Binance Launchpad Sale Allocation','25,000,000 HOOK'), ('Binance Launchpad Sale Price','0.10 USD / HOOK'), ('Binance Launchpad Amount to be Raised','2,500,000 USD'), ('Initial Circ. Supply When Listed on Binance','50,000,000 HOOK (10.00%)') ) as tbl(token_name, hook_amount))select*from token_plan
-- nft持仓成本分布-- 0x306b1ea3ecdf94ab739f1910bbda052ed4a9f949 beanz-- 0xED5AF388653567Af2F388E6224dC7C4b3241C544 azukiwith contract_transfer as (select*from nft.tradeswhere nft_contract_address = 0xe361f10965542ee57D39043C9c3972B77841F581and tx_to != 0x0000000000000000000000000000000000000000and amount_original is not null),transfer_rn as (selectrow_number() over (partitionby token_id order by block_time desc) as rn, *from contract_transfer),latest_transfer as (select*from transfer_rnwhere rn =1),min_max as (select (cast({{max_price}} as double) -cast({{min_price}} as double))/20.0as bin),bucket_trade as (select*,casewhen amount_original between {{min_price}}+0*bin and {{min_price}}+1*bin then1*binwhen amount_original between {{min_price}}+1*bin and {{min_price}}+2*bin then2*binwhen amount_original between {{min_price}}+2*bin and {{min_price}}+3*bin then3*binwhen amount_original between {{min_price}}+3*bin and {{min_price}}+4*bin then4*binwhen amount_original between {{min_price}}+4*bin and {{min_price}}+5*bin then5*binwhen amount_original between {{min_price}}+5*bin and {{min_price}}+6*bin then6*binwhen amount_original between {{min_price}}+6*bin and {{min_price}}+7*bin then7*binwhen amount_original between {{min_price}}+7*bin and {{min_price}}+8*bin then8*binwhen amount_original between {{min_price}}+8*bin and {{min_price}}+9*bin then9*binwhen amount_original between {{min_price}}+9*bin and {{min_price}}+10*bin then10*binwhen amount_original between {{min_price}}+10*bin and {{min_price}}+11*bin then11*binwhen amount_original between {{min_price}}+11*bin and {{min_price}}+12*bin then12*binwhen amount_original between {{min_price}}+12*bin and {{min_price}}+13*bin then13*binwhen amount_original between {{min_price}}+13*bin and {{min_price}}+14*bin then14*binwhen amount_original between {{min_price}}+14*bin and {{min_price}}+15*bin then15*binwhen amount_original between {{min_price}}+15*bin and {{min_price}}+16*bin then16*binwhen amount_original between {{min_price}}+16*bin and {{min_price}}+17*bin then17*binwhen amount_original between {{min_price}}+17*bin and {{min_price}}+18*bin then18*binwhen amount_original between {{min_price}}+18*bin and {{min_price}}+19*bin then19*binwhen amount_original between {{min_price}}+19*bin and {{min_price}}+20*bin then20*binELSE21*binendas gapfrom latest_transfer,min_max )select gap, count(*) as numfrom bucket_tradegroup by gaporder by gap
with contract_transfer as (select*from nft.tradeswhere nft_contract_address = 0xe361f10965542ee57D39043C9c3972B77841F581and tx_to != 0x0000000000000000000000000000000000000000and amount_original is not null),transfer_rn as (selectrow_number() over (partitionby token_id order by block_time desc) as rn, *from contract_transfer),latest_transfer as (select*from transfer_rnwhere rn =1),min_max as (select (cast({{max_price}} as double) -cast({{min_price}} as double))/20.0as bin),-- 生成一个1到20数字的单列表num_series as (select num from unnest(sequence(1, 20)) as tbl(num)),-- 生成分组价格区间的开始和结束价格bin_gap as (select (num -1) * bin as gap, (num -1) * bin as price_lower, num * bin as price_upperfrom num_seriesjoin min_max on trueunion all-- 补充一个额外的区间覆盖其他数据select num * bin as gap, num * bin as price_lower, num * 1e4 * bin as price_upperfrom num_seriesjoin min_max on truewhere num =20),bucket_trade as (select t.*, b.gapfrom latest_transfer tjoin bin_gap b on t.amount_original >= b.price_lower and t.amount_original < b.price_upper )select gap, count(*) as numfrom bucket_tradegroup by gaporder by gap
在CTEnum_series中,我们使用unnest(sequence(1, 20)) as tbl(num)来生成了一个从1到20点数字序列并且转换为20行,每行一个数字。然后在bin_gap中,我们通过JOIN两个CTE计算得到了每一个区间的低点价格值和高点价格值。使用union all集合添加了一个额外的高点价格值足够大的区间来覆盖其他交易记录。接下来bucket_trade就可以简化为只需要简单关联bin_gap并比较价格落入对应区间即可。整体上逻辑得到了简化而显得更加清晰易懂。
selectjson_query(vars, 'lax $.follower') AS follower, -- single valuejson_query(vars, 'lax $.profileIds') AS profileIds, -- still stringfrom_hex(cast(json_extract(vars,'$.follower') asvarchar)) as follower2, -- cast to varbinarycast(json_extract(vars,'$.profileIds') asarray(integer)) as profileIds2, -- cast to arrayvarsfrom lens_polygon.LensHub_call_followWithSigwhere cardinality(output_0) >1limit10