SELECT *
FROM
(SELECT date_trunc('day', block_timestamp) AS metric_date,
event_from as metric_label,
count(distinct tx_id) AS metric_value,
row_number() OVER(PARTITION BY metric_date ORDER BY metric_value DESC) as rn
FROM gold.near_events
WHERE event_to_label_type = 'project'
AND (event_from_label_type != 'project' OR event_from_label_type IS NULL)
AND metric_date >= getdate() - interval '6 months'
-- AND event_type = 'transfer'
AND event_currency = 'NEAR'
GROUP BY 1, 2)sq
WHERE rn <= 10
ORDER BY 1 DESC, 3 DESC