ChatGPT + SQL
DATA ANALYSIS POWER TIPS
*Copyright Maven Analytics, LLC
COURSE OUTLINE
Explore how AI is changing the way data analysts work, and
1 Why Analysts Need to Use AI why leveraging these tools is critical to stay competitive
Introduce the AI landscape and the role of large language
2 Intro to AI, LLMs & GPTs models and generative pre-trained transformers like ChatGPT
Review best practices for creating clear and effective prompts
3 Prompt Engineering Tips when working with tools like ChatGPT or Gemini
Explore some of the most powerful and practical ChatGPT use
4 ChatGPT + SQL Use Cases cases for data analysis with SQL
*Copyright Maven Analytics, LLC
MEET YOUR INSTRUCTORS
CHRIS DUTTON
Chris is an EdTech entrepreneur and best-selling instructor.
As Founder and Chief Product Officer at Maven Analytics, his
work has been featured by USA Today, Business Insider,
Entrepreneur and the New York Times, reaching more than
1,000,000 students around the world.
✔ Certified Excel & Power BI Expert
✔ Founder & Lead Instructor
*Copyright Maven Analytics, LLC
MEET YOUR INSTRUCTORS
JOHN PAULER
John brings over a decade of business intelligence experience
to the Maven team, having worked with companies ranging
from Fortune 500 to early-stage startups.
As a MySQL expert, he has played leadership roles across
analytics, marketing, SaaS and product teams.
✔ 15+ Years in Applied Analytics
✔ Lead MySQL Instructor
*Copyright Maven Analytics, LLC
SETTING EXPECTATIONS
This is an overview on how data professionals can use AI tools
• We’ll introduce the AI landscape and tools like ChatGPT, and review practical use cases for data analysts,
but will not dive deeply into how these models work or give an exhaustive list of everything they can do
We’ll be using free AI tools for the course demos
• We’ll quickly touch on paid options and alternative tools, but the majority of what you see in this course will
be shown using the free versions of ChatGPT and/or Google Gemini
AI is a rapidly evolving field, and these tools will change quickly
• AI technology is moving FAST, which means that existing products will change, and new vendors and tools
will emerge, but the core concepts and best practices you learn in this course will remain relevant
This course is designed be modular to fit your needs
• The first half of the course is for everyone, but the second half is structured so that you can focus specifically
on the tools you use as an analyst – feel free to skip over the tool sections that don’t apply to you!
*Copyright Maven Analytics, LLC
WHY ANALYSTS NEED TO USE AI
*Copyright Maven Analytics, LLC
WHY YOU NEED TO USE AI TOOLS
THE WORLD IS CHANGING
Technology like ChatGPT, Google Bard, and other Artificial Intelligence tools allow you to
complete tasks that used to take hours in a matter of minutes, making it a total game changer
Reasons you should learn to use AI tools:
✓ Improve your performance & efficiency
✓ Automate routine, low-value tasks
✓ Spend more time on the higher value activities
✓ Use AI as an easy way to check your work
✓ Leverage it for learning and answering quick questions
✓ Stay on the cutting edge and competitive in your field
*Copyright Maven Analytics, LLC
ARE DATA ANALYST JOBS AT RISK?
AI WILL NOT REPLACE YOU
Fears of analysts losing jobs to AI are overblown; companies will always need human talent and
intuition, but the skills required to be an effective analyst will shift substantially
We call this the “Analytics Trifecta”, because it represents the
STRATEGIC three core skills that separate a good analyst from a great one
THINKING These are uniquely
This is where AI “human” skills Since AI can fill many technical gaps, analysts with exceptional
really adds value
strategic thinking and communication skills will become more
valuable than ever to organizations
Combine those “human” skills with a strong technical
TECHNICAL COMMUNICATION foundation enhanced by AI, and you’ll be unstoppable
PROFICIENCY SKILLS
*Copyright Maven Analytics, LLC
YOU NEED AI TO STAY COMPETITIVE
IF YOU DON’T USE AI SOMEONE ELSE WILL
Imagine being a data analyst today without learning spreadsheets or using the internet. We’ll
likely be saying the same thing about ChatGPT and other AI tools in the near future.
750M+ 5B+ 1B+
users worldwide users worldwide users worldwide
The key to an enduring, successful career in Data Analytics is to build a strong foundational skill
set, and keep it sharp by embracing and adapting to modern technology
*Copyright Maven Analytics, LLC
COMMON ANALYTICS USE CASES
THIS IS WHERE AI SHINES
While there are many potential ways that data professionals can leverage AI, these are a few of
the most common and powerful use cases we’ve explored:
Generating code Explaining technical Troubleshooting or Commenting Optimizing queries
or formulas concepts debugging code or formulas
Generating step-by- Providing data Automating Researching Generating
step tutorials visualization tips manual tasks technical topics data samples
*Copyright Maven Analytics, LLC
INTRO TO AI, LLMS & CHATGPT
*Copyright Maven Analytics, LLC
THE AI LANDSCAPE
ARTIFICIAL INTELLIGENCE “Weak” vs. “Strong” Artificial Intelligence
Machines and computer systems that mimic
functions associated with human intelligence
like decision making, image recognition, etc.
Weak AI (current state)
• Can only perform specialized tasks
MACHINE LEARNING • For example, GPT-4 could tell you how to drive a car,
Statistical models that help computers learn
but couldn’t use that knowledge to drive a car itself
with minimal human instruction, and get more
accurate when exposed to more data
Strong AI (Artificial General Intelligence)
• Can learn and perform any task that a human can do
• Its development is still on the horizon
DEEP LEARNING
Complex algorithms designed to
mimic the human brain and
learn almost exclusively without While Deep Learning has its foundations in Statistics, it focuses
human intervention solely on producing accurate model outputs (not understanding
Large language models (LLMs) the underlying data or relationships)
fall in this category
These models are often called “black boxes” since they can pick up
nuances in the data that humans can’t understand or detect
*Copyright Maven Analytics, LLC
GENERATIVE AI & LLMs
Generative AI systems are deep learning models capable of generating original text, images and
other types of media in response to user prompts
• Large Language Models (LLMs) are generative AI models focused on producing text outputs specifically
• Other generative AI models include DALL-E and Midjourney, which are used to generate images
A “simple” language model: How does the model fill in the blank?
• The model doesn’t know that “Paris” is the correct response, but suggests
The capital of France is
the answer it thinks is most probable in the given context
___
• Put simply, it compared “Paris” with thousands of words and determined
The capital of France is Paris. that it had the strongest relationship with words like “capital” and “France”
• This may seem easy, but remember that the word “capital” has multiple
meanings, that France has had other capitals, and that the blank could also
be things like “beautiful”, “a popular tourist destination”, etc.
*Copyright Maven Analytics, LLC
GENERATIVE AI & LLMs
Generative AI systems are deep learning models capable of generating original text, images and
other types of media in response to user prompts
• Large Language Models (LLMs) are generative AI models focused on producing text outputs specifically
• Other generative AI models include DALL-E and Midjourney, which are used to generate images
A large language model: How does the model answer the question?
1. It looks at millions of documents for similar questions and related
When did Paris become
statements like “in 508 A.D., Paris became the capital of France”
the capital of France?
2. It is then associates the prompt with these documents, and does its best
to mimic the language from the responses
Paris became the capital of
France in the 6th century. 3. Since it has an element of randomness to account for its uncertainty, if
you ask it again it will likely tell you something similar but not identical
Large language models like ChatGPT are COLOSSAL achievements in machine learning that model the “shape” of language
*Copyright Maven Analytics, LLC
GENERATIVE PRE-TRAINED TRANSFORMERS
Generative Pre-Trained Transformers (GPTs) are a type of large language model trained on
massive text datasets, and are designed to generate outputs that mimic human-written text
GENERATIVE PRE-TRAINED TRANSFORMERS
The model generates new and The model was already trained A type of deep learning model
original natural language text, on a large dataset before that can process sequential
instead of copying and pasting being fine-tuned to perform inputs and differentiate the
existing data specific tasks importance of individual parts
(also known as self-attention)
LLMs like ChatGPT are among the most sophisticated deep learning models ever built; GPT-4, which powers premium
versions of ChatGPT, has over 1 TRILLION parameters, cost over $100 million dollars, and took 11 months to train
*Copyright Maven Analytics, LLC
A BRIEF HISTORY OF AI
AI tools like ChatGPT became widely popular in late 2022, but owe their success to more than
60 years of research and development in artificial intelligence systems
GPT4
GPT3
MODEL PARAMETERS
GPT2
GPT1
“Modern Era” of AI
The term “Artificial Intelligence” Researchers find major flaws The first neural network Transformer Layers are
Deep Blue beats
is used for the first time in the Perceptron algorithm with deep learning introduced in Neural Nets
chess champion
capabilities is developed
Gary Kasparov
The first neural network Multi-layer Perceptrons & Open AI founded, AlphaGo
algorithm is implemented Backpropagation implemented IBM Watson beats beats world champions at Go
in the same algorithm humans at Jeopardy!
ELIZA, the first chatbot, Siri & Alexa
is created at MIT Neural networks outperform other AlexNet sets a standard are launched
solutions in document recognition for image recognition
*Neural Net breakthroughs
*AI achievements *Copyright Maven Analytics, LLC
PATH TO 1 MILLION
The rate of adoption for modern AI tools is unprecedented; ChatGPT became the fastest-
growing online product in history, reaching 1 million users in only 5 days
3.5 YEARS
2 YEARS
10 MONTHS
2.5 MONTHS
5 DAYS
*Copyright Maven Analytics, LLC
COMMON AI TOOLS
Rapid advancements in AI technology and the success of ChatGPT have led to an unprecedented
explosion of new apps, services, and players in the field
Text Video
Image Code
Speech 3D Music
*Copyright Maven Analytics, LLC
CHATGPT & GEMINI
In this course, we’ll be focusing on exploring two of the most popular GPT tools on the market:
ChatGPT (from OpenAI) and Gemini (from Google)
• ChatGPT made headlines first, but Google’s Gemini (formerly Bard) emerged as a strong competitor in early 2023
These tools each have unique strengths, but are very similar in terms of benefits & limitations for data professionals
*Copyright Maven Analytics, LLC
WARNING: COMMON PITFALLS
LLMs are known to “hallucinate” facts with total confidence
• Remember that YOU are ultimately responsible for verifying the accuracy of model outputs
Solutions provided may be suboptimal or entirely incorrect
• AI tools don’t guarantee accuracy, and may provide incorrect or inefficient solutions
These tools are broad and often lack specific domain knowledge
• LLMs may not understand specific business context or the “why” behind the responses they produce
LLMs are NOT capable of common sense or human judgement
• Models need specific, objective inputs, and may miss critical context that may seem obvious to humans
*Copyright Maven Analytics, LLC
ACCESSING CHATGPT
You can access ChatGPT for free at chat.openai.com
• Open AI currently allows anyone to sign up and use
ChatGPT for free (note that there is a paid version as well)
• You can create an account using an email address, or by
connecting an existing Microsoft or Google account
• Read more information about ChatGPT on the OpenAI
website: https://openai.com/blog/chatgpt
*Copyright Maven Analytics, LLC
ACCESSING GOOGLE GEMINI
You can access Google Gemini for free at gemini.google.com
• Google made Gemini available for free in
May 2023 (available in most countries)
• You can sign up for Gemini using an existing
Google email or creating a new account
• Read more information about Gemini here:
https://gemini.google.com/faq
*Copyright Maven Analytics, LLC
PROMPT ENGINEERING
*Copyright Maven Analytics, LLC
PROMPT ENGINEERING 101
Prompts are questions or instructions that serve as the input for models like ChatGPT
• Prompt engineering is the practice of constructing prompts to generate effective and accurate responses
This is the
prompt Tips & Best Practices:
✓ Be as clear and specific as possible
This is the ✓ Provide context and examples
response
✓ Establish roles for specific use cases
✓ Set the tone or level of complexity
✓ Understand model limitations
PRO TIP: You likely won’t nail the “perfect”
prompt right away; make sure to refine and iterate
based on quality of the responses
*Copyright Maven Analytics, LLC
TIP: BE CLEAR & SPECIFIC
ORIGINAL PROMPT vs BETTER PROMPT
Can you give me an Excel formula to calculate year over year
How do you calculate year over year growth?
growth?
Data for this year lives in cells C2:C100, and data for last
year lives in cells B2:100.
PRO TIP: When generating code, include details like
variable names, data types, cell ranges, etc.
*Copyright Maven Analytics, LLC
TIP: PROVIDE CONTEXT
ORIGINAL PROMPT vs BETTER PROMPT
I’m a Data Analyst working on supply chain analytics for a
What are common supply chain KPIs?
multinational distribution company. What KPIs should I be
analyzing? For each metric, please include a formula
showing how it is calculated.
For example, we would calculate conversion rate as follows:
Conversion rate = website orders / website sessions
*Copyright Maven Analytics, LLC
TIP: ESTABLISH ROLES
ORIGINAL PROMPT vs BETTER PROMPT
I'm a new Data Analyst for a retail business, and I've been
What’s the best way to clean data?
tasked with cleaning and preparing a raw dataset for analysis.
Please play the role of a Data QA Engineer and provide a
step-by-step plan for me to follow.
*Copyright Maven Analytics, LLC
TIP: SET THE TONE
ORIGINAL PROMPT vs BETTER PROMPT
Explain regression analysis in two sentences to a C-Level
Explain regression analysis
executive at a marketing agency
PRO TIP: Use prompts like “explain it to me as if you
were speaking to a child” to adjust the tone and
complexity of the response
*Copyright Maven Analytics, LLC
CHATGPT + SQL
*Copyright Maven Analytics, LLC
CHATGPT FOR SQL
In this section we’ll explore common use cases for ChatGPT + SQL, including
generating queries, commenting code, debugging errors, and more
TOPICS WE’LL COVER: GOALS FOR THIS SECTION:
• Learn how to use AI as a personal coach, to explain
Explaining SQL Concepts Explaining SQL Queries complex SQL code or concepts
• Use AI tools to generate SQL queries from scratch
Commenting SQL Code Debugging Errors by describing your desired output
• Ask AI tools to help you debug errors in your SQL
Generating SQL Queries Optimizing Queries
queries and rewrite the code without errors
• Comment and optimize complex SQL queries with
the help of AI tools
*Copyright Maven Analytics, LLC
Explain a SQL Concept
You’ll be acting as a SQL expert. You’ll be coaching me, as a junior coworker who is
learning SQL and needs help. Can you explain the difference between a LEFT JOIN
and an INNER JOIN in SQL?
PROMPT
ENGINEERING
✓ Be as clear and specific as possible
✓ Use roles to add context and set the
tone and complexity of the response
✓ Ask for sample data, formula examples,
common use cases, etc.
✓ Iterate and use follow-up prompts to
dive deeper into specific topics
Explain a SQL Query
You’ll be acting as a Senior Analyst who is an expert in SQL. You’ll be helping me, a
junior analyst on the team, understand SQL queries that we’ll use together on the job.
Can you please explain the following query to me? [insert code sample] PROMPT
ENGINEERING
✓ Be as clear and specific as possible
✓ Use roles to add context and set the
tone and complexity of the response
✓ Provide code samples and ask for
summaries or line-by-line explanations
✓ Iterate and use follow-up prompts
until you get the focus and level of
detail you need
Add Comments to a SQL Query
You’ll be acting as a Senior Analyst who is an expert in SQL. You’ll be helping me, a
junior analyst on the team, understand SQL queries that we’ll use together on the job.
Could you add comments to this query to make it easy for other analysts to understand? PROMPT
[insert code sample] ENGINEERING
✓ Be as clear and specific as possible,
and clearly describe the desired output
✓ Use roles to add context and set the
tone and complexity of the response
✓ Iterate and use follow-up prompts
until you get the output you need
Debug SQL Code
You’ll be acting as a Senior Analyst who is an expert in SQL. You’ll be helping me, a junior
analyst on the team, troubleshoot an error. The error I’m seeing is below, and you can see
the query here. Can you correct the error and explain what you did? [insert code sample]
PROMPT
ENGINEERING
✓ Be as clear and specific as possible,
and provide specific code samples and
error details
✓ Use roles to add context and set the
tone and complexity of the response
✓ Ask for corrected code, along with a
summary of what was changed
✓ Iterate and use follow-up prompts
until you get output you need (the
initial solution may be incorrect!)
Create a SQL Query from Scratch
You’ll be acting as a SQL expert and helping me, a non-expert, create some queries to pull
data from our database. Based on the descriptions below, can you create a query to pull a
list of the most valuable students in terms of how much revenue they have generated?
PROMPT
[insert table descriptions]
ENGINEERING
✓ Be as clear and specific as possible,
and include context around table
names, descriptions, etc.
✓ Use roles to add context and set the
tone and complexity of the response
✓ Iterate and use follow-up prompts
until you get output you need (the
initial solution may be incorrect!)
Optimize a SQL Query
You’ll be acting as a SQL expert, and will be helping me, a junior member on the team,
understand how to optimize my SQL query to improve its performance.
Can you please write the query below in a more efficient way, and explain to me the PROMPT
changes you made like I’m someone who is new to SQL? [insert code sample] ENGINEERING
✓ Be as clear and specific as possible
✓ Use roles to add context and set the
tone and complexity of the response
✓ Ask for optimized code along with a
clear summary of the changes made
✓ Iterate and use follow-up prompts
until you get the output you need
WRAPPING UP
*Copyright Maven Analytics, LLC
KEY TAKEAWAYS
Tools like ChatGPT will change the way data professionals work
• Analysts will need to adapt and evolve to new technology to stay competitive in the age of AI
AI isn’t perfect, and may “hallucinate” or provide incorrect responses
• Remember that YOU are ultimately responsible for verifying the accuracy of the model output
Prompt engineering can dramatically improve response quality
• Be specific, provide meaningful context, and iterate to produce accurate and relevant responses
AI tools can be applied to many types of analytics use cases
• Tools like ChatGPT can help troubleshoot or generate code, automate tasks, and much more
*Copyright Maven Analytics, LLC
NEXT STEPS
In terms of AI revolutionizing the way analysts work, ChatGPT and Gemini are only the beginning
• Just like the internet at the turn of the century, AI tools will fundamentally change the future of work
Our Advice:
✓ Stay up to date with new tools & technology
• The AI industry is evolving quickly, so make sure to follow the latest news and developments from trusted
companies and thought leaders in the space
✓ Be curious, but skeptical
• While we expect some amazing new AI developments in the coming years, we also expect to see some
unrealistic promises from companies trying to capitalize on the hype
✓ Build a well-rounded skill set
• As tools like ChatGPT begin to automate more complex technical tasks, focus on developing your uniquely
“human” skills like problem solving, strategic thinking, communication and business acumen
*Copyright Maven Analytics, LLC