Querying data using SQL

Why SQL? (a brief overview)

At the heart of our data exploration and analytics features lies SQL , the cornerstone of modern data management and analysis. Here’s why SQL is integral to our products:

  • Declarative Simplicity: SQL’s declarative nature allows users to focus on specifying the data they want to retrieve, rather than detailing the procedural steps to get there. This shift from "how to do" to "what to do" simplifies data manipulation into intuitive commands, making complex data operations accessible to a broader audience.

  • Low Learning Curve: Unlike procedural programming languages that require detailed instructions (e.g., Python, Java, Rust), SQL’s simplicity and intuitive syntax mean that users can quickly learn how to query data effectively. This ease of learning opens up data analysis to professionals across various fields, not just to those with specialized programming skills.

  • Universal Standardization: With its long history of success and widespread adoption, SQL has been standardized by ANSI. This standardization ensures that SQL skills and knowledge are highly transferable and remain relevant across different data systems.

Token Flow data, as it's name already suggests it - Multi-chain Data Warehouse, is stored in a data warehouse. Using SQL is the obvious choice.

SQL Basics

There are a variety of training and course available for learning SQL with various degrees of complexity. For the 60s intro to SQL, here are 5 things you need to know to get you started:

  • SELECT – list of columns to return, or use asterisk (*) to indicate all columns

  • FROM – one or more tables, that contain the data

  • WHERE – filters to reduce data returned from tables

  • GROUP BY – in aggregations, specifies which columns drive the grouping, while all other columns must be wrapped in an aggregate function like SUM()

  • ORDER BY – specifies the order in which data is returned

And here is an example that uses the 5 elements presented above.

	day(block_timestamp) as day, 
	sum(tx_count) as tx_count
from MCDW.blocks
where block_timestamp >= '2024-01-01'
group by day
order by day desc

Last updated