Ali3NNew vs Existing Traders Over Time (Kaiaswap Kaia)
    Updated 2024-10-16
    with timetable as (
    select case when '{{TimeFrame}}' = 'Last 7 Days' then 7
    when '{{TimeFrame}}' = 'Last 30 Days' then 30
    when '{{TimeFrame}}' = 'Last 60 Days' then 60
    when '{{TimeFrame}}' = 'Last 90 Days' then 90
    when '{{TimeFrame}}' = 'Last 180 Days' then 180
    when '{{TimeFrame}}' = 'Last 365 Days' then 365
    when '{{TimeFrame}}' = 'All Time' then 5000
    else 5000 end as timeframe),

    maintable as (
    select block_timestamp,
    platform,
    tx_hash,
    origin_from_address,
    amount_in_usd,
    row_number () over (partition by origin_from_address order by block_timestamp asc) as rn
    from kaia.defi.ez_dex_swaps
    where platform ilike '%kaiaswap%')

    select date_Trunc ({{Date_Trunc}},block_timestamp) as date,
    case when rn = 1 then 'New Traders' else 'Existing Traders' end as type,
    count (distinct tx_hash) as Swaps_Count,
    count (distinct origin_from_address) as Traders_Count
    from maintable t1 join timetable
    where block_timestamp >= current_date - timeframe
    group by 1,2
    order by 1 desc



    QueryRunArchived: QueryRun has been archived