WITH LIQUID AS (
SELECT
date as fecha,
sum(balance) as liquid
FROM
terra.daily_balances
WHERE
currency ='LUNA'
AND balance_type = 'liquid'
AND balance > 0
GROUP BY 1
),
STAKE AS (
SELECT
date as fecha,
sum(balance) as staked
FROM
terra.daily_balances
WHERE
currency ='LUNA'
AND balance_type = 'staked'
AND balance > 0
GROUP BY 1
)
SELECT
l.fecha,
sum(l.liquid),
sum(s.staked)
FROM LIQUID l
INNER JOIN stake s
ON l.fecha = s.fecha