Query editor
with daily_metrics as (selectdate--, collateral_token_symbol as symbol, pool-- Multiply, count(*) as liquidations, sum(amount_deposited_usd) as liquidate_earn_amount_usd-- , sum(amount_borrowed_usd) as liquidate_borrow_amount_usdfrom dune.vesu.result_vesu_v_2_metrics_log_data -- log datawhere is_liquidate = 1group by 1,2)-- select * from daily_metrics, date_series AS (WITH dates AS (SELECT sequence(cast('2025-09-22' as date),cast(date_trunc('day', current_timestamp) AS date),interval '1' day) as d)SELECT date_value as dateFROM datesCROSS JOIN UNNEST(d) AS t(date_value)), pools AS (SELECT DISTINCT poolFROM daily_metrics), date_pool_series AS (SELECT DISTINCTds.date,s.poolFROM date_series dsCROSS JOIN pools s),tmp as (SELECT DISTINCT dss.date, s.pool, COALESCE(s.liquidations,0) as liquidations, COALESCE(s.liquidate_earn_amount_usd, 0) as liquidate_earn_amount_usdFROM date_pool_series dssLEFT JOIN daily_metrics s ON dss.date = s.date AND dss.pool = s.pool)selectcase when '{{period}}'='day' then datewhen '{{period}}'='week' then date_trunc('week', date)when '{{period}}'='month' then date_trunc('month', date)end as date, coalesce(pool, '') as pool, sum(liquidations) as liquidations, sum(liquidate_earn_amount_usd) as liquidate_earn_amount_usdfrom tmpgroup by 1,2