How do I find the top 10 customers by revenue with AI?
Recipe verified on
Ran on the public demo (read-only)
Short answer
Have your AI group the orders by customer, sum the revenue, sort it descending and keep ten rows. With a database behind it that's one query over every order, so the ranking is exact even with millions of rows.
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, who are the top 10 customers by total revenue in Demo.Orders?
What your AI does: the tool call it makes for this prompt, and what came back
query(table_name="Demo.Orders", group_by=["customer_id"], agg=[{"func": "sum", "column": "revenue", "alias": "revenue"}, {"func": "count", "column": "order_id", "alias": "orders"}], sort=[{"column": "revenue", "desc": true}], limit=10) → 10 rows (more available)
| customer_id | revenue | orders |
|---|---|---|
| 119438 | 60,657.04 | 73 |
| 151096 | 57,983.66 | 65 |
| 186717 | 57,948.18 | 69 |
| 25899 | 56,686.13 | 58 |
| 198726 | 56,061.86 | 71 |
| 62715 | 55,974.64 | 68 |
| 56632 | 55,786.98 | 64 |
| 141887 | 55,581.91 | 62 |
| 28374 | 55,460.29 | 61 |
| 29863 | 55,275.86 | 82 |
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
A top-N needs every row: a customer whose orders sit at the end of a file the AI only partly read would be missed. The database sorts the totals and returns ten rows, so the conversation holds the answer, not the data.