Text to SQL: aggregation queries from plain English

Ask about totals, averages, medians, or distributions. Chion selects the right aggregation function based on column type classification and validates the GROUP BY against your schema.

How Chion handles aggregations

Column type classification drives aggregation choice.

Column type classification drives aggregation choice. Quantitative columns get SUM or AVG depending on intent. Categorical columns get COUNT or COUNT(DISTINCT). The contract rejects mismatched aggregations before execution.

If GROUP BY produces too many groups, the pipeline coarsens time grain first, then applies TopK ranking — but never auto-filters dates.

Examples: English → aggregation queries

GROUP BY, HAVING, COUNT, SUM, AVG, and PERCENTILE_CONT.

"Revenue by region last quarter"GROUP BY + date filter
SELECT region, SUM(revenue) AS total_revenue
FROM orders
WHERE order_date >= date_trunc('quarter', CURRENT_DATE - INTERVAL '3 months')
  AND order_date < date_trunc('quarter', CURRENT_DATE)
GROUP BY region
ORDER BY total_revenue DESC;
"Median order value by city"PERCENTILE_CONT
SELECT city,
  PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY order_value) AS median_value
FROM orders
GROUP BY city;
"Regions with revenue over $1M"GROUP BY + HAVING
SELECT region, SUM(revenue) AS total
FROM orders
GROUP BY region
HAVING SUM(revenue) > 1000000
ORDER BY total DESC;
"Average order value by customer segment"JOIN + AVG
SELECT segment, AVG(order_value) AS avg_value
FROM orders
JOIN customers ON customers.id = orders.customer_id
GROUP BY segment;

Aggregation FAQ

Try aggregation queries in plain English

Connect your PostgreSQL database and ask about totals, averages, or distributions.