Smarter Week

How to automate it

How to automate “write and debug SQL queries”

Here are 2 ways to spend less time on this, best first. Each comes with steps you can follow today and, for AI fixes, a prompt to copy.

60 min
typically, every day
50%
of the time can be automated
Easy
to set up

Fix 1 of 2

AIBest fix

Write and fix SQL with the AI in your SQL editor

Snowflake Copilot, Databricks Assistant, BigQuery with Gemini, Hex Magic and DataGrip AI know your schema and can write, explain and fix queries. You check joins and filters.

Typically saves about 35% of the time10 min to set up
  1. 1Turn on the AI assistant in your warehouse or SQL editor.
  2. 2Describe the result you need in plain English, naming the tables if you know them.
  3. 3Read the query: check joins, filters, date ranges and how it handles nulls and duplicates.
  4. 4Run it on a small sample and compare a known total before you trust it.
  5. 5Without a built-in assistant, paste the schema and use the prompt below in an approved chat tool.
Prompt to copy
Write a [SNOWFLAKE / BIGQUERY / POSTGRES / T-SQL] query that returns [WHAT YOU NEED], grouped by [BREAKDOWN], for [DATE RANGE]. Tables and columns:
[PASTE SCHEMA]
Rules: [e.g. exclude test accounts, revenue is net of refunds]. Explain each join and any assumption about duplicates or nulls. Then suggest one check I can run to confirm the totals are right.

Tools: Snowflake Copilot · Databricks Assistant · BigQuery with Gemini · Hex Magic · DataGrip AI · ChatGPT, Claude, Gemini or Microsoft Copilot

Fix 2 of 2

Automation

Define metrics once in a semantic layer that every tool reads from

When "revenue" or "active user" is defined once in dbt's Semantic Layer, LookML, Cube or Power BI semantic models, reports stop disagreeing and AI tools give consistent answers.

Typically saves about 40% of the time20 h to set up
  1. 1List the 10 metrics that cause the most arguments.
  2. 2Agree the definition of each with the business owner and write it down.
  3. 3Build them in your semantic layer (dbt Semantic Layer, LookML, Cube, or a shared Power BI semantic model).
  4. 4Point dashboards and natural-language BI tools at the semantic layer, not raw tables.
  5. 5Retire the old calculations in individual reports.

Tools: dbt Semantic Layer · Looker LookML · Cube · Power BI semantic models · Snowflake semantic views

Quick wins

Have you tried…

Have you used the AI assistant built into your SQL editor or warehouse to write or fix queries?
Snowflake Copilot, Databricks Assistant, BigQuery with Gemini and Hex know your tables and can write a query from a plain-English description. You check the joins and filters.
Are your key metrics defined once in a semantic layer that every dashboard uses?
A semantic layer (dbt Semantic Layer, LookML, Cube, Power BI semantic models) stores the official definition of each metric, so every report and AI tool calculates it the same way.

Who does this task

Roles in our library that list this as one of their common tasks. Each guide covers the rest of that role’s week.

HourLeak · the 8-minute work audit

How many hours does this cost you?

The free 8-minute check works out where your week goes and gives you your top fixes. The team scan does the same for everyone and adds it up, so you know which leaks to fix first.

Answers are anonymous. Leaders only see team totals.

Other common tasks for Data / BI analysts