Sample SQL Query

Example: Query all trades on Osmosis DEX and order them by Pool

SELECT
	count(*) as Trades,
	attribute_value as Pool_ID
FROM `numia-data.osmosis.osmosis_event_attributes`
WHERE event_type = 'token_swapped'
AND attribute_key = 'pool_id'
GROUP BY 2
ORDER BY 1 desc;

Example: Query the staking balance of a user in Celestia at a certain block height

SELECT sender, SUM(token_amount) AS token_amount
  FROM (
    SELECT sender, token_amount 
    FROM `numia-data.celestia.celestia_delegate`
    WHERE sender = 'celestia1r0gmufmz9em8anlxd8exygwwllhk3ny6g4hqlz'
    and block_height <= 1654914

    UNION ALL

    SELECT sender, -token_amount
    FROM `numia-data.celestia.celestia_undelegate`
    WHERE sender = 'celestia1r0gmufmz9em8anlxd8exygwwllhk3ny6g4hqlz'
    and block_height <= 1654914
  )
  GROUP BY sender
  ORDER BY token_amount DESC
```

💡 Tip: For a primer in SQL queries, visit https://www.w3schools.com/sql/

Last updated