TheLaughingMan[NEAR][T3] Ref Finance Calls By Function
    Updated 2022-08-11
    with base as (
    SELECT
    date_trunc('day', a.block_timestamp) as ddate,
    a.tx_hash,
    receipt_index,
    receiver_id,
    tx_signer,
    tx_receiver,
    logs,
    method_name,
    tx
    from near.core.fact_receipts a
    LEFT JOIN near.core.fact_transactions t ON a.tx_hash = t.tx_hash
    LEFT JOIN near.core.fact_actions_events_function_call f ON a.tx_hash=f.tx_hash
    WHERE 1=1
    AND receiver_id='v2.ref-finance.near'
    --AND (a.tx_hash = '9PTe5i2iV7CgHdHFj5zyL7TTRATKege6bG3z7PzD2VGN' OR a.tx_hash='zzwK6JTxtSNFhWX2k7gfvuA7ZgfkxrfokpS4F71y9K8')
    --AND (tx_receiver = 'v2.ref-finance.near' OR args LIKE '%\"receiver_id\":\"v2.ref-finance.near\"%')
    --AND tx not ilike '%"status":{"Failure"%'
    ),

    pre as (
    SELECT
    COUNT(DISTINCT tx_hash) as totals,
    method_name,
    ddate
    from base
    GROUP BY ddate, method_name ORDER BY ddate ASC
    )

    SELECT *,
    rank() OVER (PARTITION BY ddate ORDER BY totals DESC) as rank
    from pre
    qualify rank<=5

    Run a query to Download Data