Multipartite2022-05-25 Terra pool RUNE depths
    Updated 2022-05-25
    WITH
    depths AS
    (
    SELECT DISTINCT block_timestamp, block_id, pool_name,
    CAST(POWER(10,-8) * rune_e8 AS DECIMAL(17,8)) AS rune_depth
    FROM thorchain.block_pool_depths
    WHERE pool_name IN ('TERRA.UST', 'TERRA.LUNA')
    ),

    rowcounting AS
    (
    SELECT
    COUNT(depths.*) AS rowcount,
    10000 AS target_rows
    FROM depths
    )
    SELECT depths.*
    FROM depths, rowcounting
    QUALIFY (
    (MOD((ROW_NUMBER() OVER(ORDER BY block_id ASC)), CEIL(rowcount/target_rows)) = 0)
    --Row-sampling.
    OR (ROW_NUMBER() OVER(ORDER BY block_id ASC) = 1)
    --Include the first data point.
    OR (ROW_NUMBER() OVER(ORDER BY block_id DESC) = 1)
    --Include the last data point.
    )
    ORDER BY block_id DESC
    Run a query to Download Data