mcpdata Request an invite

Answers / Analyse data

How do I find the min and max per group?

Recipe verified on Ran on the public demo (read-only)
Short answer

Ask for min and max of the column with a group-by. Your AI gets the lowest and highest value per group in one query, here the smallest and largest order per product category, with the order count.

Steps

  1. 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.

  2. Ask your question. Give your AI this prompt:
    Using mcpdata, for each category in Demo.Orders, what are the smallest and largest order revenue?
What your AI does: the tool call it makes for this prompt, and what came back
query(table_name="Demo.Orders", group_by=["category"], agg=[{"func": "min", "column": "revenue", "alias": "smallest"}, {"func": "max", "column": "revenue", "alias": "largest"}, {"func": "count", "column": "order_id", "alias": "orders"}], sort=[{"column": "category", "desc": false}]) → 12 rows
What you should get · the recipe's real result from its last run
categorysmallestlargestorders
Accessories8.56564.72740,027
Audio26.562,090.16881,049
Cameras209.689,361.31835,065
Gaming27.042,878.48760,056
Laptops571.8111,736.00860,772
Monitors116.495,179.84915,522
Networking27.111,758.42825,900
Phones237.947,184.52855,129
Smart Home18.081,887.12829,541
Software12.551,415.12745,506
Storage35.553,409.00907,269
Tablets155.075,623.45849,164

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

Extremes are exactly what sampling misses: the largest order is, by definition, rare. The database scans every row for each group, so the min and max are the real ones.

Related questions