JustSQL GPT: Making BigQuery Easier for Everyone

Jason Tragakis
JustDataPlease
Published in
3 min readJan 31, 2024

Ever wanted to perform customer segmentation analysis by simply asking a question in plain English, without compromising your data’s privacy?

JustSQL is revolutionizing how we interact with Google BigQuery, turning complex data queries into a straightforward, user-friendly process — you ask, and JustSQL delivers the SQL code.

JustSQL GPT is free but requires a ChatGPT Plus account to use it.

You can install the JustSQL GPT plugin here (you will be redirected to ChatGPT).

How Does JustSQL GPT Work?

JustSQL GPT streamlines the process of generating SQL queries through a few simple steps:

1. Install JustSQL GPT

Install JustSQL GPT by visiting https://justdataplease.com/justsql-assistant-bigquery-gpt/ (you will be redirected to ChatGPT)

2. Generate Your Schema

For JustSQL understand the data structure, you need to provide your tables schema.
To do so, you need to run the following SQL statement in your BigQuery Console (part of Open-Source UDF library JustFunctions).

-- Make sure to replace your_project_id, your_dataset_id, table1 with your own
CALL `justfunctions.eu.generate_justsql_schema`('your_project_id', 'your_dataset_id', ['table1', 'table2'])

This will return a schema in JSON format, like the example below.

{
"tables":[
{
"table_name": "your_project_id.your_dataset_id.transactions",
"columns": [
{"name": "order_id", "type": "INT64"},
{"name": "user_id", "type": "INT64"},
{"name": "amount", "type": "FLOAT64"},
{"name": "completed_at", "type": "TIMESTAMP"}
]
},
{
"table_name": "your_project_id.your_dataset_id.customers",
"columns": [
{"name": "user_id", "type": "INT64"},
{"name": "email", "type": "STRING"}
]
}
]
}

3. Copy & Paste your schema to ChatGPT console

4. Ask in Plain Language

Whether it’s customer segmentation, sales analysis, or any other simple data inquiry, just ask in simple English. JustSQL is designed to comprehend and convert these into SQL queries.

For example:

Perform Customer Segmentation analysis.

This will return the following SQL statement.

-- This query calculates the total spending per customer and classifies them into segments such as 'High Spenders', 'Medium Spenders', and 'Low Spenders', based on their spending amount. Adjust the thresholds in the CASE statement according to your specific segmentation criteria.

WITH CustomerSpending AS (
SELECT
c.user_id,
SUM(t.amount) AS total_spending
FROM
`your_project_id.your_dataset_id.transactions` t
JOIN
`your_project_id.your_dataset_id.customers` c ON t.user_id = c.user_id
GROUP BY
c.user_id
)

SELECT
user_id,
total_spending,
CASE
WHEN total_spending >= 1000 THEN 'High Spenders'
WHEN total_spending >= 500 AND total_spending < 1000 THEN 'Medium Spenders'
WHEN total_spending < 500 THEN 'Low Spenders'
ELSE 'Undefined'
END AS Spending_Segment
FROM
CustomerSpending
ORDER BY
total_spending DESC

The above SQL Statement is tailored to your question, ready for use in BigQuery. It’s fast, efficient, and requires no SQL expertise.

5. Run the Generated SQL

Run the given SQL query in BigQuery for immediate insights into customer behavior!

Key Features of JustSQL

  1. Effortless Use: JustSQL is made for everyone — no need for deep SQL knowledge.
  2. JustFunctions Integration: Enhances queries with advanced functionalities from JustDataPlease’s JustFunctions Open-Source UDF library.
  3. Built Specifically for BigQuery: Ensures seamless integration and optimized performance.
  4. Complex Queries Made Simple: Handles any query with ease, maintaining high performance and readability.
  5. Privacy-Centric: JustSQL generates queries without needing access to your database, ensuring your data’s privacy.

Conclusion

JustSQL makes complex data analysis accessible to everyone by translating natural language queries into SQL for BigQuery, eliminating the need for deep technical expertise in SQL without compromising on privacy and efficiency. This democratizes data analysis, allowing users to focus on insights rather than learning complex SQL syntax.

--

--