Query editor
WITH day AS (SELECT DISTINCT DATE(minute) AS day, symbolFROM prices.usdWHEREDATE(minute) > TRY_CAST('2021-08-08' AS TIMESTAMP)AND (contract_address = 0xae7ab96520de3a18e5e111b5eaab095312d7fe84OR contract_address = 0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0OR contract_address = 0xae78736cd615f374d3085123a210448e74fc6393OR contract_address = 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48OR contract_address = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2OR symbol='ETH')ORDER BY day DESC),detail as (select day, token, sum(amount) over(partition by token order by day) as amountfrom(SELECT date_trunc('day', block_time) as day, token, sum(if(in_out = 'in', amount, -amount)) as amountFROM query_3280176where in_out != 'internal'group by 1, 2)),total AS (SELECT a.day, a.symbol, b.day AS day2,if(b.amount < 0, 0, b.amount) as amountFROM day AS aJOIN detail AS bON a.symbol = b.token),total2 as(SELECT day,symbol, max(day2) as day2FROM totalwhere day2<daygroup by 1,2),h_value as (select a.day, a.symbol, max(b.amount) as amount--max(b.value_usd) as value_usd,--max(b.value_eth) as value_ethfrom total2 a join total bon a.day2=b.day2 and a.symbol=b.symbolgroup by 1,2),price as (SELECTsymbol,date(minute) as day,max(price) as priceFROM prices.usdWHERE contract_address = 0xae7ab96520de3a18e5e111b5eaab095312d7fe84or contract_address = 0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0or contract_address =0xae78736cd615f374d3085123a210448e74fc6393or contract_address =0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48or contract_address =0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2or symbol='ETH'group by 1,2 order by 2 desc)--,--价格和精度--result as(select a.day, a.symbol,case when a.symbol != 'stETH' then a.amount else c.amount end as amount,case when a.symbol != 'stETH' then a.amount*b.price else c.value_usd end as value_usd,--sum(a.amount*b.price) over(partition by a.day) as total_value_usd,case when a.symbol != 'stETH' then a.amount*b.price/(select b.price from price b where b.symbol ='ETH' and a.day=b.day) else c.value_eth end as value_eth--sum(a.amount*b.price/(select b.price from price b where b.symbol ='ETH' and a.day=b.day)) over (partition by a.day) as total_value_eth