# SQL Query Generator: Write and Fix Queries in Slack

Source: https://maito.app/workflows/write-and-fix-sql

Describe what you need or paste a broken query in Slack. Maito writes or fixes the SQL, runs it on BigQuery or Supabase, and explains what went wrong.

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

[Data](https://maito.app/workflows/team/data) · When you ask · Updated October 19, 2026

Works with

-   Slack
-   Email
-   [BigQuery](https://maito.app/workflows/tool/bigquery)
-   [Supabase](https://maito.app/workflows/tool/supabase)

## 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

**Nina** (1:20 PM):

Fix this query; it double counts orders. Attached: orders\_revenue.sql.

**Maito** (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):

Include the 17.

**Maito** (1:33 PM):

Done. Those 17 orders add $4,120, so the total is $402,360. Attached: orders\_revenue\_fixed\_v2.sql.

## 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

### Does it run the query on my data?

It can run read queries through BigQuery or Supabase to check that the output makes sense. It does not change data unless your team has set that up and approved it.

### Can it fix a query that gives wrong numbers?

Yes. It looks for common causes such as duplicated joins and filters that drop rows, shows the difference in the result, and attaches the fixed query.

### Will it know my table and column names?

It reads them from the connected database, so it uses your real schema rather than guessing.

## More data workflows

-   [Answer data questions in Slack Ask a question in plain words and get the number, with the query behind it. Data · When you ask Works with BigQuery, Supabase.](https://maito.app/workflows/answer-data-questions-in-slack)
-   [Chart a metric Get a chart of any metric over time, ready to paste into a deck. Data · When you ask Works with BigQuery, Supabase.](https://maito.app/workflows/chart-a-metric)
-   [Explain a dashboard number Know what a number means and how it's calculated. Data · When you ask Works with BigQuery, Supabase, Notion, Confluence.](https://maito.app/workflows/explain-a-dashboard-number)
-   [Check data for problems Spot missing data, duplicates and sudden jumps before anyone trusts a bad number. Data · On a schedule Works with BigQuery, Supabase.](https://maito.app/workflows/check-data-for-problems)
-   [Send a weekly metrics digest Key numbers for the company every Monday, with what changed and why. Data · On a schedule Works with BigQuery, Supabase, Stripe, PayPal.](https://maito.app/workflows/send-a-weekly-metrics-digest)
-   [Review possible duplicate customers before merging See why two customer records might be the same person, then decide. Nothing merges on a shared name. Data · When something happens Works with HubSpot, Salesforce, Airtable, Microsoft 365.](https://maito.app/workflows/review-possible-duplicate-customers-before-merging)

[See all workflows](https://maito.app/workflows)

## Put your AI teammate to work.

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

[Put Maito to work](https://maito.app/login?returnTo=%2Fworkflows%2Fwrite-and-fix-sql)[Book a demo](mailto:support@maito.app?subject=Maito%20demo)
