Coefficient's AI SQL Builder lets you create SQL queries directly in Google Sheets or Excel without having to write everything from scratch. You can simply enter a prompt or describe the data you want to import, and the AI assistant will generate the SQL query for you. Whether you're new to SQL or an experienced user, you can also edit and refine queries as needed, making it easier to get the data you need.
Examples of AI SQL Builder Prompts and Outputs
ℹ️ NOTE: Coefficient's AI SQL Builder has schema awareness, so you don’t need to manually specify your data schema when describing the SQL query you want to build.
Using AI SQL Builder
ℹ️ EXAMPLE: Create a MySQL import to count the number of movies per genre using AI SQL Builder.
|
1. Open the Coefficient sidebar and click "Import from...".
|
2. Select your (MySQL) data source connection.
|
3. Choose "AI SQL Builder".
|
4. The Import Preview window opens, allowing you to enter your description/prompt, select your table schema, then click "Generate SQL" (eg, "Count the number of movies for each genre.")
5. The AI SQL Builder will update, showing you the SQL query at the top and a sample of the data output results at the bottom.
6. To make changes to the generated query, you can ask the AI SQL Builder by adding new prompts and clicking the "Generate SQL" button again. (eg, "Include a total at the bottom").
ℹ️ PRO TIP: Click on the "Refresh Preview" button to update the data output preview if you manually make changes to the query.
7. Click "Import" and make sure you give this import a UNIQUE name (eg, "Movies by genre").
8. Congratulations on your first successful import using the AI SQL Builder with Coefficient! 🎉
Edit Existing Query
You can edit an existing SQL query in a few quick steps using Coefficient’s AI SQL Builder.
|
1. Open the Coefficient sidebar and click on your existing import (eg, Movies by genre). |
2. Click the "Edit SQL" button. |
3. The Import Preview window opens, and you can manually edit the raw query, or click "Use AI to write a query..." to ask the AI to make the edits for you.
4. Describe the change you'd like to make and click "Generate SQL". The query will update, and the new results (a sample) will appear underneath the query window in the preview. Click " Done " when your edits are complete.
5. The preview window will close, and the sidebar will automatically refresh your import to update the data on your sheet. 🎉
Examples of AI SQL Builder Prompts and Outputs
Select Queries
| Input ("Describe the query") | Output (Raw Query) |
| "Show me a list of all movies released before the year 2000." | |
| "What are the top 10 highest-rated movies in the dataset?" | |
| "Count the number of movies released in the 1990's." | |
Join Queries
| Input ("Describe the query") | Output (Raw Query) |
| "Retrieve the movie title and the name of the actor who played in each movie." | |
| "Which actors have appeared in the most movies?" | |
| "Which actresses have worked in the highest-rated movies?" | |
Group By Queries
| Input ("Describe the query") | Output (Raw Query) |
| "Count the number of movies for each genre." | |
| "Calculate the average rating for each genre." | |
| "Find the total number of movies released in each year." | |
Order By Queries
| Input ("Describe the query") | Output (Raw Query) |
| "Sort movies by their rating in descending order." | |
| "Sort actors by their names in alphabetical order." | |
| "Sort movies by their release year in ascending order." | |
Date Function Queries
| Input ("Describe the query") | Output (Raw Query) |
| "What is the time difference between the release years of Jon Favreau's latest movie releases? | |
| "Find movies released between 1995 and 2000." | |
| "What are the release months of all the movies in the database?" | |
FAQs for AI SQL Builder
Do I need to specify my data schema when describing my SQL query?
No, the AI SQL Builder is designed to be schema-aware, meaning it can automatically detect and work with the schema associated with your data to generate SQL queries.
Which data schema does AI SQL Builder use?
The AI SQL Builder uses your default schema when generating queries. If your data source has multiple schemas, a dropdown will appear, allowing you to select a different schema. By default, SQL Builder automatically selects your default schema as the target for query generation.
Can the AI SQL Builder write cross-schema queries?
Unfortunately, the AI SQL Builder does not support cross-schema queries. This means you can only interact with and generate queries within the default/selected schema.
Which AI model does the AI SQL Builder use?
Coefficient's AI SQL Builder leverages advanced AI models from leading providers, including OpenAI, to deliver powerful and accurate assistance.