with tab1 AS
(select
hour::date as date1 ,
avg(price) as "USD price ETH"
from ethereum.token_prices_hourly
where token_address = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
group by 1),
tab2 AS
(select
hour::date as date ,
CASE
WHEN token_address = '0xe95a203b1a91a908f9b9ce46459d101078c2c3cb' THEN 'aETH'
WHEN token_address = '0xae78736cd615f374d3085123a210448e74fc6393' THEN 'rETH'
WHEN token_address = '0xae7ab96520de3a18e5e111b5eaab095312d7fe84' THEN 'stETH'
END as "token name",
avg(price) as "USD price tokens"
from ethereum.token_prices_hourly
where token_address in ('0xe95a203b1a91a908f9b9ce46459d101078c2c3cb','0xae78736cd615f374d3085123a210448e74fc6393',
'0xae7ab96520de3a18e5e111b5eaab095312d7fe84' )
and hour >= CURRENT_DATE - 286
group by 1, 2
)
SELECT
date ,
"token name",
"USD price tokens" - "USD price ETH" as "diff price with wETH",
("diff price with wETH"/ "USD price ETH")*100 as "diff price percentage"
from tab1 a
join tab2 b on a.date1=b.date