-- -- 两个方向
-- -- 1.获取某些dalao的共同购买的token以及token的购买人数
-- -- 2.获取某些dalao 针对某些token的购买时间，获取是否是早期购买者
-- -- 为了节省private 空间 公用一个。


 

-- --第一个方向代码 
-- --开始 开始 开始 开始 开始 开始 开始 开始 开始
-- --获取某些dalao的共同购买的token以及token的购买人数

WITH
    input_address (address) as (
        values
            ('5ENKzVezTxEYtZzF1W4mM1s3LjU6b2oBw8af2827ULKb'),
            ('5FSt9LxycNWfdXFmhuDbYonoGcnBJDjZYvqC3ZuA9RGc'),
            ('UKCC5vtp2U5281ZSaSqafDbb9aFcrj84BKsf6p5Aqxm'),
            ('SGd7pJkt1heW4pTWLBHVtMoqaN1Anvvbb5wp5Juktrb'),
            ('81XZEmB4eYXqdXktnZRVDaiyFbp6hATgygjK98QSbtXq'),
            ('2oViQCbm1JWWwvvKeq2zsAns1cT48WDTk77aS7ZAPnjJ'),
            ('EW5o2Nr2oHdr8YbWfdAFkcpxT2bqvi2jdDpaTepvoQNa'),
            ('EWpftEEZJ7AJyGJprctqc131qQtpjWkoJahM1D9xdTiH'),
            ('CJT24gYwv6Sadbj6jUb6ESnm6jYYZdBEzZoeH84C35tq'),
            ('6frSrTT9aarJuBWKE36uBQJDh3VcSHWeP7Hdhar9ap7g'),
            ('ALNngQwBnooVP41YWGM6yJZSLHTQ3eVZMaAKc9yigWTj'),
            ('HUzZ1MrEUXrdPJoAnn5B8uTcshwyyXxFW1EqY2dvcVhe'),
            ('CMGdz9VBDDmc5uoZFxux4Jv1gYxoUW1Xdu8NxfijCTxJ'),
            ('5BkT4TNnJE7Zq2s3DmGExGSjL7JpJBnxa6atsjARbkxS'),
            ('ArHmZWQxH3j29X7nw6xzeFnLrYdywnEKz3oE2zpwXHtd'),
            ('9wYuJBuoBiNDxk97ZmCqdaBjB3gZ1iFnEBU2Jme3phpV'),
            ('H9kHjTaJqVrrSuZGwJWgQnjyhVmGANpqsA6eoqbbZrTk'),
            ('2swb9pJ9Ak5TLBsfsBcr5QVCStM5vNZAcyhRY9uZTSi5'),
            ('DZm7P5hZBLFKzFqy4JzQaxUnWRkrr3AwDMa2kCrGr4Nc'),
            ('J3ctoNuCEGXD63rf84GfgkXYczt7F6uycpVczzK57MfH'),
            ('5RANC5iQzzeLFcr1D42Pih4ksUMfa7KXMoCkzoRhujuP'),
            ('8jzB2HEK322ntFCfzUwajUt9hjYA25L9F8LangTcPfMY'),
            ('5sEVaCVRRyfWPhw54c4z3h59ZvJ9tL5xK2tYfT4gQnDZ'),
            ('A2U5owsnFK2jzgBguZCDqXsPzra7ufpYG5N6CFCeQrk6')
    ),
    temp_01 AS (
        SELECT
            trader_id,
            block_time,
            tx_id,
            token_bought_mint_address as token_address,
            token_sold_mint_address,
            (token_bought_amount / 1e6) as token_amount_M,
            token_sold_amount as sol_amount
        FROM
            dex_solana.trades t
            inner join input_address on (input_address.address = t.trader_id)
        WHERE
            (
                (
                    -- token_bought_mint_address = 'So11111111111111111111111111111111111111112'
                    -- OR 
                    token_sold_mint_address = 'So11111111111111111111111111111111111111112'
                )
                and (
                    -- 购买token数目超过0.5M
                    token_bought_amount > 0.5 * 1e6
                    -- token_sold_amount >1
                )
                and (
                    block_time > timestamp '2025-03-01 00:00:00 +08:00'
                    and block_time < timestamp '2025-03-18 12:00:00 +08:00'
                )
            )
    ),
    every_trader_goumai_every_token_info as (
        select
            trader_id,
            token_address,
            min(block_time) as block_time
            -- ,( to_unixtime(CAST(min(block_time) AS timestamp))-1700000000) AS block_time
,
            sum(token_amount_M) as token_amount_M,
            sum(sol_amount) as sol_amount,
            count(block_time) as buy_count
        from
            temp_01
        group by
            trader_id,
            token_address
    ),
    every_token_trader_chiyou_renshu as (
        select
            token_address,
            min(block_time) as min_block_time,
            max(block_time) as max_block_time,
            count(*) as trader_number
        from
            every_trader_goumai_every_token_info
        group by
            token_address
    ),
    every_token_trader_chiyou_renshu_he_token_create_time_he_trade_buy_time as (
        SELECT
            token_address,
            min_block_time
            -- ,max_block_time
,
            trader_number,
            p_c.call_block_time as create_time
        FROM
            every_token_trader_chiyou_renshu
            left join pumpdotfun_solana.pump_call_create p_c on every_token_trader_chiyou_renshu.token_address = p_c.account_mint
    )
select
    *
from
    every_token_trader_chiyou_renshu_he_token_create_time_he_trade_buy_time
where
    trader_number >= 4
order by
    trader_number desc
 

-- 第一个方向代码 
-- 结束 结束 结束 结束 结束 结束 结束 结束 结束



 

 

-- -- --第二个方向代码 
-- -- --开始 开始 开始 开始 开始 开始 开始 开始 开始
-- -- --获取某些dalao 针对某些token的购买时间，获取是否是早期购买者

-- WITH
--     input_address (address) as (
--         values
--             ('5ENKzVezTxEYtZzF1W4mM1s3LjU6b2oBw8af2827ULKb'),
--             ('5FSt9LxycNWfdXFmhuDbYonoGcnBJDjZYvqC3ZuA9RGc'),
--             ('UKCC5vtp2U5281ZSaSqafDbb9aFcrj84BKsf6p5Aqxm'),
--             ('SGd7pJkt1heW4pTWLBHVtMoqaN1Anvvbb5wp5Juktrb'),
--             ('81XZEmB4eYXqdXktnZRVDaiyFbp6hATgygjK98QSbtXq'),
--             ('2oViQCbm1JWWwvvKeq2zsAns1cT48WDTk77aS7ZAPnjJ'),
--             ('EW5o2Nr2oHdr8YbWfdAFkcpxT2bqvi2jdDpaTepvoQNa'),
--             ('EWpftEEZJ7AJyGJprctqc131qQtpjWkoJahM1D9xdTiH'),
--             ('CJT24gYwv6Sadbj6jUb6ESnm6jYYZdBEzZoeH84C35tq'),
--             ('6frSrTT9aarJuBWKE36uBQJDh3VcSHWeP7Hdhar9ap7g'),
--             ('ALNngQwBnooVP41YWGM6yJZSLHTQ3eVZMaAKc9yigWTj'),
--             ('HUzZ1MrEUXrdPJoAnn5B8uTcshwyyXxFW1EqY2dvcVhe'),
--             ('CMGdz9VBDDmc5uoZFxux4Jv1gYxoUW1Xdu8NxfijCTxJ'),
--             ('5BkT4TNnJE7Zq2s3DmGExGSjL7JpJBnxa6atsjARbkxS'),
--             ('ArHmZWQxH3j29X7nw6xzeFnLrYdywnEKz3oE2zpwXHtd'),
--             ('9wYuJBuoBiNDxk97ZmCqdaBjB3gZ1iFnEBU2Jme3phpV'),
--             ('H9kHjTaJqVrrSuZGwJWgQnjyhVmGANpqsA6eoqbbZrTk'),
--             ('2swb9pJ9Ak5TLBsfsBcr5QVCStM5vNZAcyhRY9uZTSi5'),
--             ('DZm7P5hZBLFKzFqy4JzQaxUnWRkrr3AwDMa2kCrGr4Nc'),
--             ('J3ctoNuCEGXD63rf84GfgkXYczt7F6uycpVczzK57MfH'),
--             ('5RANC5iQzzeLFcr1D42Pih4ksUMfa7KXMoCkzoRhujuP'),
--             ('8jzB2HEK322ntFCfzUwajUt9hjYA25L9F8LangTcPfMY'),
--             ('5sEVaCVRRyfWPhw54c4z3h59ZvJ9tL5xK2tYfT4gQnDZ'),
--             ('A2U5owsnFK2jzgBguZCDqXsPzra7ufpYG5N6CFCeQrk6')
--     ),
--     input_token (mint_address) as (
--         values
--             ('5CuCQwjejaAyc7Z1HfmzJHfRrrV8HPfPfgaazuzpump'),
--             ('CKCwS3gq4DHpvAD5FYCZq6qsZjaTv9mp67kYh4Vbpump'),
--             ('8eq6uKMYtJ2npJC2YGj2LCZ5xKZFX3TuB2LTXB9Epump'),
--             ('BzBHziaQZqSBKd8DXqrNgsDNd75i7CB5hH1rsQRxpump'),
--             ('hV7MQkCpjvuTTnPJXPhPXzvmtMxk8A8ct1KPiRMpump'),
--             ('AhJ2u3o7CK4sPk9WQ2rr8FwG1xSTBMMqkjXZbeqapump'),
--             ('B92orCCYZ3J5kBzPDNRP9Sj1oC9cx2X289Myateopump'),
--             ('Ey4tXRVTiLtjZJE33T96KYxJ8TDdVyV7uDn6FuDCpump'),
--             ('4QYaccriCgnrb3rxpibqv5vj7Wba669YBqvNEVeJpump'),
--             ('9LTnCiXxqZm29PpeQpzAAHadgWiPBkxESJqUKPSvpump'),
--             ('HxQVaDCJT5HnRMSE8dFv8sDGdLQ5RSASrccYdBaDpump'),
--             ('8TcALAM4U7MMnuRiqMBf8pEsdnt94uknpg2jepEgpump'),
--             ('J8rZcqDBXWCtmz9C4qhdfiRA5ZQQjasa5aeghbnxpump'),
--             ('Bx8NMNm84Pw6s7N688cWvDr8CDudgjz329vyqkoGpump'),
--             ('2WLd1HqbPutTh1gowWFzkgGG9PgzVcnvqUs4iNXopump'),
--             ('BhwwEnvzsEdncGWdDZv2airsw1HZVbRBBGfYhgZfpump'),
--             ('G8VxZiVvkpbjcvcxMm1btLHjJrdfz9CdqXy44tM9pump'),
--             ('3DRnsQ5GA2XKk8WJ3yB46KbcRWGtA3E6cgFaqzJWpump'),
--             ('9zeStqRxC8TfJE71hbTkQV4xBSHc5LFnTUa54K9sGE1i'),
--             ('6zipf14FCZusfwF8FeyUP851XytF5T55oLdgARE5qyKK')
--     ),
--     temp_01 AS (
--         SELECT
--             trader_id,
--             block_time,
--             tx_id,
--             token_bought_mint_address as token_address,
--             token_sold_mint_address,
--             (token_bought_amount / 1e6) as token_amount_M,
--             token_sold_amount as sol_amount
--         FROM
--             dex_solana.trades t
--             inner join input_address on (input_address.address = t.trader_id)
--             inner join input_token on (
--                 input_token.mint_address = t.token_bought_mint_address
--             )
--         WHERE
--             (
--                 (
--                     -- token_bought_mint_address = 'So11111111111111111111111111111111111111112'
--                     -- OR 
--                     token_sold_mint_address = 'So11111111111111111111111111111111111111112'
--                 )
--                 and (
--                     -- 购买token数目超过0.5M
--                     token_bought_amount > 0.5 * 1e6
--                     -- token_sold_amount >1
--                 )
--                 and (
--                     block_time > timestamp '2025-03-01 00:00:00 +08:00'
--                     and block_time < timestamp '2025-03-18 12:00:00 +08:00'
--                 )
--             )
--     ),
--     every_trader_goumai_every_token_info as (
--         select
--             trader_id,
--             token_address,
--             min(block_time) as block_time,
--             sum(token_amount_M) as token_amount_M,
--             sum(sol_amount) as sol_amount,
--             count(block_time) as buy_count
--         from
--             temp_01
--         group by
--             trader_id,
--             token_address
--     ),
--     every_token_trader_token_create_time_he_dif_trade_buy_time as (
--         SELECT
--             token_address,
--             trader_id,
--             (
--                 to_unixtime(
--                     CAST(
--                         every_trader_goumai_every_token_info.block_time AS timestamp
--                     )
--                 ) - to_unixtime(CAST(p_c.call_block_time AS timestamp))
--             ) / 60 AS buy_create_time_diff,
--             p_c.call_block_time as create_time
--         FROM
--             every_trader_goumai_every_token_info
--             left join pumpdotfun_solana.pump_call_create p_c on every_trader_goumai_every_token_info.token_address = p_c.account_mint
--     ),
--     every_token_trader_chiyou_renshu_he_token_create_time_he_dif_trade_buy_time as (
--         select
--             *,
--             COUNT(*) OVER (
--                 PARTITION BY
--                     token_address
--             ) AS trader_number
--         from
--             every_token_trader_token_create_time_he_dif_trade_buy_time
--     )
-- select
--     *
-- from
--     every_token_trader_chiyou_renshu_he_token_create_time_he_dif_trade_buy_time


-- -- 第二个方向代码 
-- -- 结束 结束 结束 结束 结束 结束 结束 结束 结束







