winnie-fscooing-tan
Updated 2024-09-12
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
›
⌄
WITH first_buy AS (
SELECT
OWNER AS trader_id,
MINT AS token_mint_address,
MIN(BLOCK_TIMESTAMP) AS first_buy_time
FROM solana.core.fact_token_balances
WHERE OWNER = '7fdevSbQubj4Bc6NLfn2UdMS8Npioi5XyDKwLbKjw43k'
GROUP BY OWNER, MINT
),
price_history AS (
SELECT
p.ASSET_ID AS token_mint_address,
p.HOUR AS block_timestamp,
p.CLOSE AS price_usd -- Precio de cierre por hora
FROM solana.price.fact_prices_ohlc_hourly AS p
JOIN first_buy AS fb
ON p.ASSET_ID = fb.token_mint_address
WHERE p.HOUR >= fb.first_buy_time
)
SELECT DISTINCT
fb.trader_id,
fb.token_mint_address,
fb.first_buy_time,
MAX(ph.price_usd) AS max_price_after_buy
FROM first_buy AS fb
JOIN price_history AS ph
ON fb.token_mint_address = ph.token_mint_address
GROUP BY fb.trader_id, fb.token_mint_address, fb.first_buy_time
ORDER BY fb.token_mint_address;
QueryRunArchived: QueryRun has been archived