Embark on a journey of simplified data analysis with our knowledge article on using Coefficient's SQL Builder to construct SQL queries directly within Google Sheets. Explore how this integration streamlines the query creation process, making it accessible for users of all SQL expertise levels. Whether you're a data novice or a seasoned analyst, discover the efficiency of leveraging GPT to generate SQL queries and unlock insights from your Google Sheets data effortlessly. Join us in exploring the powerful combination of artificial intelligence and spreadsheet functionality.
*This feature is currently supported on Google Sheets only*
Examples of SQL Builder Prompts and Outputs
ℹ️ NOTE: SQL Builder has schema awareness, eliminating the necessity for you to explicitly specify the data schema while describing your SQL query!
ℹ️ NOTE: The following databases are supported by Coefficient's SQL Builder:
- Snowflake
- PostgreSQL
- MySQL
- RedShift
- MS SQL
Using SQL Builder
1. Open the Coefficient Sidebar and click GPT Copilot. |
2. Select "Chart Builder" from the list of options. |
3. Select a supported database source for your import using SQL Builder. |
4. Select "GPT SQL Builder" from the import options. |
5. The Import Preview window opens allowing you to enter your description/prompt, select your table schema, then click "Generate SQL".
6. SQL Builder will update showing you the query at the top, a sample of the data output results below the query. Click "Import" and make sure you give this import a UNIQUE name.
7. Congratulations on your first successful import using SQL Builder with Coefficient! 🎉
Edit Existing Query
Modifying an existing SQL query through SQL Builder is a straightforward process.
1. Navigate to your import from the home screen and select the "Edit SQL" button.
2. You can click into the raw query and make the necessary edits or use AI to make the edits for you. Click inside the AI SQL Builder prompt box and add in a description of what you would like to modify on your existing query, then click "Generate SQL".
3. The query will update and the new results will be shown (a sample) underneath the query window. Click done with your edits are complete.
4. The preview window will close. You will need to "Save & Run" for the edits to be applied to the import and the new results incorporated into your import.
Prompt History
There may be times when you would like to see the previous prompts that you tried using SQL Builder with Coefficient. You can access your Prompt History within the import preview window, by clicking the prompt/description box and any prompts that you created during that current session will be listed there.
ℹ️ NOTE: Prompt History is retained throughout each session, allowing you to view previous prompts during the import preview. However, closing the import preview window will reset the history, providing a fresh start with a new session.
Examples of 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." |
SELECT movie_title,release_date |
"What are the top 10 highest-rated movies in the dataset?" |
SELECT movie_title,rating |
"Count the number of movies released in the 1990's." |
SELECT COUNT(*)AS movie_count |
Join Queries
Input ("Describe the query") | Output (Raw Query) |
"Retrieve the movie title and the name of the actor who played in each movie." |
SELECT m.movie_title,a.actor_name |
"Which actors have appeared in the most movies?" |
SELECT a.actor_name, COUNT(*) AS movie_count |
"Which actresses have worked in the highest-rated movies?" |
SELECT a.actress_name, AVG(m.rating)AS average_rating |
Group By Queries
Input ("Describe the query") | Output (Raw Query) |
"Count the number of movies for each genre." |
SELECT g.genre_name, COUNT(*) AS movie_count |
"Calculate the average rating for each genre." |
SELECT g.genre_name, AVG(m.rating) AS average_rating |
"Find the total number of movies released in each year." |
SELECT YEAR(release_date) AS release_year, COUNT(*) AS movie_count |
Order By Queries
Input ("Describe the query") | Output (Raw Query) |
"Sort movies by their rating in descending order." |
SELECT movie_title,rating |
"Sort actors by their names in alphabetical order." |
SELECT actor_name |
"Sort movies by their release year in ascending order." |
SELECT movie_title, release_date |
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? |
SELECT DATEDDIFF(YEAR,MIN(release_date),MAX(release_date)) |
"Find movies released between 1995 and 2000." |
SELECT movie_title,release_date |
"What are the release months of all the movies in the database?" |
SELECT DISTINCT EXTRACT(MONTH FROM release_date) AS release_month |
FAQs for SQL Builder
What databases are supported for SQL Builder?
The following databases are supported by Coefficient's SQL Builder:
- Snowflake
- PostgreSQL
- MySQL
- RedShift
- MS SQL
Do I need to specify my data schema when describing my SQL query?
No, the 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 is used with SQL Builder?
SQL Builder employs the default schema for your data when generating queries. In the case of having multiple schemas, a dropdown appears to select different schemas. SQL Builder automatically selects your default schema as the target for query generation.
Can SQL Builder write cross-schema queries?
Unfortunately, the SQL Builder does not support cross-schema queries. This means that you can only interact with and generate queries within the confines of the default schema.
Which GPT model does the SQL Builder use?
SQL Builder uses GPT 4 Turbo as it offers the best compromise by far between costs, speed, and quality.
Why isn't SQL Builder available for my schema?
If you are unable to see SQL Builder for your schema, it may be due to limitations of OpenAI related to the size of your schema. OpenAI cannot handle massive schemas, and if your schema exceeds the limit set, the SQL Builder feature will be disabled.