SocioCryptocompare token_id digits
    Updated 2024-01-14
    -- forked from BlockTracker / compare nft digit @ https://flipsidecrypto.xyz/BlockTracker/q/setIBuusCi8J/compare-nft-digit

    with sales as (
    SELECT DISTINCT tx_id
    FROM sei.core.fact_msg_attributes
    WHERE attribute_key = 'nft_address'
    and attribute_value = 'sei1pkteljh83a83gmazcvam474f7dwt9wzcyqcf5puxvqqs6jcx8nnq2y74lu'
    AND MSG_TYPE = 'wasm-buy_now'
    )
    ,
    nft as (
    SELECT
    tx_id,
    ATTRIBUTE_VALUE as nft_id
    FROM sei.core.fact_msg_attributes
    WHERE tx_id in (SELECT tx_id FROM sales)
    AND ATTRIBUTE_KEY = 'token_id' AND MSG_TYPE = 'wasm'
    ),
    price as (
    SELECT
    tx_id,
    (CASE when attribute_value ilike 'native:%' then substr(attribute_value, 13,24)
    else split(attribute_value, 'usei')[0]
    end)/1e6 as price
    FROM sei.core.fact_msg_attributes
    WHERE attribute_key = 'sale_price' and tx_id in (SELECT tx_id FROM sales)
    )
    , main as (
    SELECT
    nft_id,
    price,
    CASE
    WHEN LENGTH(TO_VARIANT(nft_id)) = 1 THEN '1 Digit'
    WHEN LENGTH(TO_VARIANT(nft_id)) = 2 THEN '2 Digits'
    WHEN LENGTH(TO_VARIANT(nft_id)) = 3 THEN '3 Digits'
    WHEN LENGTH(TO_VARIANT(nft_id)) = 4 THEN '4 Digits'
    QueryRunArchived: QueryRun has been archived