omer9329-6 Aug secondary sales 2
    Updated 2024-08-13
    with
    info as (
    SELECT
    tx_id,block_timestamp, count(distinct CASE WHEN msg_type = 'wasm-buy_now' AND attribute_key = 'nft_token_id' THEN attribute_value END) AS nft_id,
    MAX(CASE WHEN msg_type = 'wasm-buy_now' AND attribute_key = 'nft_seller' THEN attribute_value END) AS seller,
    MAX(CASE WHEN msg_type = 'wasm-buy_now' AND attribute_key = 'sale_price' THEN attribute_value END) AS attribute_value,
    --MAX(CASE WHEN msg_type = 'wasm-buy_now' AND attribute_key = 'sale_price' THEN REPLACE(attribute_value, 'usei', '')::DECIMAL / 1000000 END) AS sei_price,
    MAX(CASE WHEN msg_type = 'coin_spent' AND attribute_key = 'spender' THEN attribute_value END) AS buyer,
    MAX(CASE WHEN msg_type = 'wasm-buy_now' AND attribute_key = 'nft_address' THEN attribute_value END) AS collection
    FROM
    sei.core.fact_msg_attributes
    where block_timestamp >= '2024-07-20'
    GROUP BY
    tx_id,block_timestamp
    having collection in ('sei1ccqar77782xutkjnhx8wmufhqx076xxmma5ylfzzvl3kg2t6r6uqv39crm',
    --'sei1kgqzuxd4lgyjrrjxhk0mkp08wedfqxfgl3humwg2tgzjylvkl8rqdflnrt',
    'sei1ck9znqxdwmmuepymgwk3dckxvsy9sddt5cq3hzcdxg8d7whyrsystvd37x'
    )

    UNION

    SELECT
    tx_id,block_timestamp, sum(CASE WHEN msg_type = 'wasm-accept_bid' AND (attribute_key = 'nft_token_id' or attribute_key='token_id') THEN 1 END) AS nft_id,
    MAX(CASE WHEN msg_type = 'wasm-accept_bid' AND attribute_key = 'seller' THEN attribute_value END) AS seller,
    MAX(CASE WHEN msg_type = 'wasm-accept_bid' AND attribute_key = 'sale_price' THEN attribute_value END) AS attribute_value,
    --MAX(CASE WHEN msg_type = 'wasm-accept_bid' AND attribute_key = 'sale_price' THEN REPLACE(attribute_value, 'usei', '')::DECIMAL / 1000000 END) AS sei_price,
    MAX(CASE WHEN msg_type = 'wasm-accept_bid' AND attribute_key = 'bidder' THEN attribute_value END) AS buyer,
    MAX(CASE WHEN msg_type = 'wasm-accept_bid' AND attribute_key='collection_address' and attribute_index=1 THEN attribute_value END) AS collection
    FROM
    sei.core.fact_msg_attributes
    where block_timestamp>=current_date-INTERVAL '1 WEEK'
    GROUP BY
    tx_id,block_timestamp
    having collection in ('sei1ccqar77782xutkjnhx8wmufhqx076xxmma5ylfzzvl3kg2t6r6uqv39crm',
    --'sei1kgqzuxd4lgyjrrjxhk0mkp08wedfqxfgl3humwg2tgzjylvkl8rqdflnrt',
    'sei1ck9znqxdwmmuepymgwk3dckxvsy9sddt5cq3hzcdxg8d7whyrsystvd37x'
    QueryRunArchived: QueryRun has been archived