DeFiScholarSession 1 - Date Manipulation & Aggregates copy
    Updated 2025-03-14
    -- forked from sam / Session 1 - Date Manipulation & Aggregates @ https://flipsidecrypto.xyz/sam/q/wSZcYxAc1Jg9/session-1---date-manipulation-aggregates

    /*
    date manipulations - date trunc vs ::date . Hour, day, month, year
    filtering with dates >=
    Aggregations: Sum, max
    CTEs
    contract address
    */

    -- select
    -- block_timestamp,
    -- block_timestamp::date,
    -- date_trunc('hour', block_timestamp),
    -- date_trunc('day', block_timestamp) as days,
    -- date_trunc('week', block_timestamp),
    -- date_trunc('month', block_timestamp),
    -- date_trunc('year', block_timestamp)
    -- from base.core.fact_transactions
    -- where days >= '2025-01-01'
    -- limit 10

    -- tx fees by address by day
    -- select
    -- block_timestamp::Date as days ,
    -- from_address,
    -- sum(tx_fee) as total_tx_fee,
    -- avg(tx_fee),
    -- median(tx_fee),
    -- max(tx_fee),
    -- min(tx_fee),
    -- count(1), -- this just counts how many rows
    -- count(*)
    -- from base.core.fact_transactions
    -- where block_timestamp::date between '2025-03-01' and '2025-03-10'
    -- and from_address in (
    Last run: 3 months ago
    DAYS
    SYMBOL
    DAILY_WETH_USD_VALUE
    1
    2025-02-07 00:00:00.000WETH30067321389.854
    2
    2025-02-02 00:00:00.000WETH781987100650.1
    3
    2025-02-10 00:00:00.000WETH40271165286.5435
    4
    2025-02-04 00:00:00.000WETH316990164976.083
    5
    2025-02-05 00:00:00.000WETH24526193629.5906
    6
    2025-02-03 00:00:00.000WETH327914339059.561
    7
    2025-02-09 00:00:00.000WETH41311011627.4104
    8
    2025-02-06 00:00:00.000WETH24521225798.4196
    9
    2025-02-01 00:00:00.000WETH590609552447.601
    10
    2025-02-08 00:00:00.000WETH35721549700.6762
    10
    518B
    4s