Write and fix SQL

Get a working query from a description, or fix a broken one.

Data · When you ask · Updated

Works with

How do you generate or fix a SQL query?

To generate or fix a SQL query, describe the result you want or attach the broken query in Slack. Maito reads your BigQuery or Supabase schema, writes or repairs the SQL, checks the result against your data, and explains the cause of any error, such as a join that counts rows twice.

How it's done today

Analysts help others with queries all day.

What Maito does

  1. Read the request and schema
  2. Write or fix the query
  3. Explain it

Example

data
Nina 1:20 PM

@Maito Fix this query; it double counts orders. Attached: orders_revenue.sql.

Maito APP 1:25 PM

Found it. The join to refunds is one row per refund, so an order with two partial refunds appears twice. Revenue came out at $412,880 instead of $398,240, which is 3.7% too high. 61 orders have more than one refund. Fix: total the refunds per order first, then join. The catch: the filter status != 'cancelled' also drops rows where status is empty, because empty never equals anything. 17 orders vanish that way. I kept your behavior, but you probably do not want it. I ran it on BigQuery for last month and got $398,240. Attached: orders_revenue_fixed.sql.

Nina 1:31 PM

@Maito Include the 17.

Maito APP 1:33 PM

Done. Those 17 orders add $4,120, so the total is $402,360. Attached: orders_revenue_fixed_v2.sql.

Example complete

How to set it up

When you ask Write and fix SQL
Set up

Nothing to set up. Ask in Slack or by email whenever you need it.

Connect database
  • BigQuery
  • Supabase

Not connected yet? Your agent sends you a link to sign in.

What it won't do

Maito cannot know which table or column your team treats as the source of truth unless the schema or a doc says so. It will ask instead of picking one.

Questions

More data workflows

See all workflows

Put your AI teammate to work.

Set it up in minutes. Start with this one, and let it earn the next one.