WITH buys AS (
SELECT
swapper AS wallet,
swap_to_mint AS token,
SUM(swap_to_amount) AS tokens_bought,
SUM(swap_from_amount * COALESCE(swap_from_decimal_price, 0)) AS cost_usd
FROM solana.defi.fact_swaps
WHERE swapper = '{{wallet_address}}'
AND block_timestamp >= CURRENT_DATE - 30
GROUP BY 1, 2
),
sells AS (
SELECT
swapper AS wallet,
swap_from_mint AS token,
SUM(swap_from_amount) AS tokens_sold,
SUM(swap_to_amount * COALESCE(swap_to_decimal_price, 0)) AS revenue_usd
FROM solana.defi.fact_swaps
WHERE swapper = '{{wallet_address}}'
AND block_timestamp >= CURRENT_DATE - 30
GROUP BY 1, 2
)
SELECT
b.token,
b.tokens_bought,
COALESCE(s.tokens_sold, 0) AS tokens_sold,
b.cost_usd,
COALESCE(s.revenue_usd, 0) AS revenue_usd,
COALESCE(s.revenue_usd, 0) - b.cost_usd AS pnl_usd
FROM buys b
LEFT JOIN sells s ON b.token = s.token
ORDER BY pnl_usd DESC
Google BigQuery (Solana Warehouse)
Google BigQuery provides access to Solana blockchain data through the public dataset bigquery-public-data.crypto_solana_mainnet_us. This is a fully managed warehouse with no indexing required and virtually unlimited compute for large-scale analysis.
Setting Up BigQuery
- Go to console.cloud.google.com and create a project
- Navigate to BigQuery in the left sidebar
- Search for
crypto_solana in the public datasets explorer
- Pin the dataset to your project for easy access
BigQuery offers 1 TB of free query processing per month. For most Solana analysis tasks, this is more than enough. Billing kicks in at $6.25 per TB scanned after the free tier.
BigQuery Schema Overview
The Solana public dataset includes:
transactions — Full transaction data including instructions and logs
blocks — Block-level metadata (slot, timestamp, leader)
accounts — Account state snapshots
token_transfers — Decoded SPL token transfer events
rewards — Validator and staking rewards
Example: NFT Sales History
SELECT
t.block_timestamp,
t.signatures[OFFSET(0)] AS tx_signature,
tt.source AS seller,
tt.destination AS buyer,
tt.value / 1e9 AS price_sol
FROM `bigquery-public-data.crypto_solana_mainnet_us.transactions` t,
UNNEST(t.token_transfers) tt
WHERE tt.mint = '{{nft_collection_mint}}'
AND t.block_timestamp >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 90 DAY)
AND t.success = TRUE
ORDER BY t.block_timestamp DESC
LIMIT 500
BigQuery shines for historical analysis across large time ranges where other platforms might time out. Scanning a full year of Solana DEX data is routine on BigQuery but can be painful on platforms with execution time limits.
Platform Comparison
| Feature | Dune Analytics | Flipside Crypto | Helius | Google BigQuery |
|---|
| SQL dialect | DuneSQL (Trino) | Snowflake SQL | N/A (API) | GoogleSQL |
| Free tier | 2,500 queries/mo | 5,000 query-sec/mo | 100K credits/mo | 1 TB queries/mo |
| Data freshness | Near real-time | Near real-time | Real-time | 1-6 hour lag |
| Query speed | Moderate | Fast | Instant (API) | Fast for large scans |
| Decoded DEX data | Yes | Yes | Via parsed tx | Limited |
| NFT sales tables | Yes | Yes | Via DAS API | Raw transfers only |
| Wallet labels | Community | Built-in | No | No |
| Visualization | Built-in charts | Built-in charts | No | Looker Studio |
| API access | Paid plans | Pro plan | All plans | All plans |
| Best for | Community dashboards, research | Clean data models, wallets | Real-time data, app backends | Large-scale historical analysis |
Choosing the right platform:
- Exploratory analysis and sharing: Start with Dune. The community queries save you hours of work, and you can fork existing dashboards.
- Clean wallet and DeFi analysis: Use Flipside. The curated data models and wallet labels make profitability queries straightforward.
- Real-time application data: Use Helius. When your app needs fresh data with millisecond latency, an API beats a query platform.
- Large historical scans: Use BigQuery. Scanning months of data without timeout limits is where BigQuery excels.
For a broader comparison of analytics tools, see our guide on the best Solana analytics dashboards.
Practical Tips for Solana SQL Queries
Optimize for cost and speed:
- Always filter by
block_time or block_timestamp first. Time-partitioned columns dramatically reduce the amount of data scanned.
- Use
LIMIT during development. A query that returns 10 million rows wastes compute even if you only look at the first 100.
- Avoid
SELECT * on transaction tables. Solana transactions contain nested instruction data that inflates scan size.
Handle Solana-specific quirks:
- Token amounts are stored as integers. Divide by
10^decimals to get human-readable values. Most platforms provide a decimal column or pre-divided amount.
- A single Solana transaction can contain dozens of inner instructions. When counting "trades" or "transfers," be specific about which instruction types you include.
- Wallet addresses on Solana are base58-encoded. Most SQL platforms store them as strings, so text matching and grouping works normally.
Combine platforms for the best results:
Use Dune or Flipside for discovery and exploration, then move to Helius or BigQuery for production pipelines that need reliability and freshness. Many analysts use Dune to prototype a query, then replicate it in BigQuery for scheduled reporting.
For deeper guidance on working with historical Solana data, check out our historical data access and analysis guide. If you want production-grade freshness instead of a warehouse query, our guide to building a Solana token analytics dashboard shows how to combine several of these same data sources into one live view, while our breakdown of the dual-region gRPC pipeline behind MadeOnSol's KOL tracker covers what real-time ingestion looks like without SQL at all. Before you write a query, it's often faster to sanity-check a wallet, token, or transaction by hand in a block explorer first — our guide to Solana FM's Translator feature shows how to read holder distributions and parsed transactions without touching a single line of SQL.
Frequently Asked Questions
Is it free to query Solana data with SQL?
Yes, every platform covered in this guide offers a free tier that is sufficient for learning and moderate analysis. Dune provides 2,500 free query executions per month, Flipside offers 5,000 query-seconds, Google BigQuery includes 1 TB of free query processing, and Helius gives 100,000 API credits. You can accomplish serious research without paying anything. Paid tiers become necessary when you need private queries, higher execution limits, or programmatic API access for production applications.
Which platform has the freshest Solana data?
Helius provides the freshest data because it queries the Solana blockchain directly via RPC and API calls, giving you real-time results with no indexing delay. Dune Analytics and Flipside Crypto both operate at near real-time freshness, typically lagging by a few minutes as they index and decode new blocks. Google BigQuery has the longest delay, often ranging from one to six hours depending on the dataset refresh schedule. If your analysis requires data from the most recent blocks, Helius is the best choice. For anything older than an hour, all four platforms provide equivalent data.
Can I use these SQL platforms to build automated trading strategies?
You can use them for the analytical component of a trading strategy, but none of these platforms are designed for real-time trade execution. Dune and Flipside are best suited for backtesting strategies, identifying patterns, and generating watchlists. Helius can feed real-time data into a trading bot via its API and webhooks. BigQuery works well for batch analysis that runs on a schedule. The typical workflow is to use SQL analysis to identify opportunities, then execute trades through a separate system connected to Jupiter or Raydium. See our on-chain data analysis guide for more on turning data into actionable insights.
Do I need to know advanced SQL to get useful results?
Basic SQL knowledge is enough to extract significant value from Solana data. If you can write SELECT, WHERE, GROUP BY, and JOIN statements, you can answer most common questions about token holders, trading volumes, and wallet activity. Dune and Flipside both have large libraries of community queries you can fork and modify without writing anything from scratch. More advanced techniques like window functions, CTEs, and subqueries become useful for complex analyses like wallet profitability tracking or time-series comparisons, but you can learn these incrementally as your questions get more sophisticated.