djebril2023-08-25 06:40 PM
    Updated 2023-08-25
    with

    pricet as (
    select
    hour::date as date,
    token_address,
    avg(price) as usdprice
    from ethereum.core.fact_hourly_token_prices
    group by 1,2
    )
    ,

    main as (
    select
    tX_hash,
    block_timestamp,
    symbol,
    amount_paid*usdprice as usd_amount,
    payer as user
    from ethereum.maker.ez_repayments
    join pricet on trunc(block_timestamp,'day')=pricet.date and token_paid=token_address
    where TX_STATUS = 'SUCCESS'
    ),

    main2 as (
    select
    user,
    count(distinct block_timestamp::date) as active_days,
    datediff('day',min(block_timestamp),to_date(current_date)) as age,
    count(distinct tx_hash) as transactions,
    sum(usd_amount) as volume_usd
    from main
    group by 1
    )

    select
    Run a query to Download Data