How do I compare two time periods in one query?
Filter to both periods and group by the period as well as what you're comparing. Your AI asks for revenue by region for 2024 and 2025 in one query and gets a row per region and year, ready to put side by side.
Steps
- Connect your assistant to the public demo. It's a read-only instance with 10 million synthetic orders,
so you can try this before you have your own. In Claude Code:
claude mcp add --transport http mcpdata-demo https://demo.mcpdata.org/mcp --header "Authorization: Bearer cdb_live_PkVoldus8qcE-hqffjajNZzQwiA7rTHMoR4RLSAxsCE"
The key is public on purpose: it can only read the demo's sample data. For Claude Desktop, Cursor and other apps, see Connect your AI.
- Ask your question. Give your AI this prompt:
Using mcpdata, compare total revenue by region in 2024 and 2025 from Demo.Orders.
| region | order_year | revenue |
|---|---|---|
| Americas | 2024 | 751,617,490 |
| Americas | 2025 | 864,417,603 |
| APAC | 2024 | 359,678,461 |
| APAC | 2025 | 413,867,443 |
| EMEA | 2024 | 678,537,780 |
| EMEA | 2025 | 782,256,894 |
Synthetic data: the demo's orders are generated, not real customers.
The assistant needs mcpdata connected (step 1) to run the query.
Why this works
Two separate queries can drift (different filters, a typo in one). One query with both years in the filter and the year in the group-by guarantees both periods are counted the same way. For a ready-made side-by-side layout, a saved view can use SUM(CASE WHEN order_year = 2025 THEN revenue ELSE 0 END).