0-MIDAverage,Minimum And Maximum Monthly DAI borrowed
Updated 2023-04-13
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
32
33
34
35
36
›
⌄
with act1 as(
with tab1 as (
select tx_hash
from ethereum.maker.ez_vault_creation),
tab2 as (
select date_trunc('month',BLOCK_TIMESTAMP) as month,tx_hash
from ethereum.maker.ez_deposits
where TOKEN_DEPOSITED='0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
)
select tab2.tx_hash
from tab1
left join tab2
on tab1.tx_hash=tab2.tx_hash),
act2 as (
select date_trunc('month',BLOCK_TIMESTAMP)as month,tx_hash,AMOUNT_USD,CASE
when month>='2019-01-01'and month< '2020-01-01' then '2019'
when month>='2020-01-01'and month< '2021-01-01' then '2020'
when month>='2021-01-01'and month< '2022-01-01' then '2021'
when month>='2022-01-01' then '2022' end as year
from ethereum.core.ez_token_transfers
where CONTRACT_ADDRESS='0x6b175474e89094c44da98b954eedeac495271d0f'
and FROM_ADDRESS='0x0000000000000000000000000000000000000000'
group by 1,2,3,4)
select month,sum(AMOUNT_USD)as dai_borrowed,year
,avg(dai_borrowed)over(order by month asc)as avg_borrowed
,max(dai_borrowed)over(order by month asc)as max_borrowed
,min(dai_borrowed)over(order by month asc)as min_borrowed
from act1
left join act2
on act1.tx_hash=act2.tx_hash
where AMOUNT_USD is not null
group by 1,3
order by 1
Run a query to Download Data