Webinar Intro To Data Analytics SQL Fundamentals

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 39

Industry Overview Applied Examples FAQ’s Take Action!

Welcome to Thinkful!
We teach tech skills that lead to fulfilling, high-paying careers.

Our students learn in-demand industry


tools through 100% online programs as
they work toward a job-ready portfolio
with the help of an expert mentor.

Let’s get started.


Industry Overview Applied Examples FAQ’s Take Action!

❏ What Is SQL?

Workshop ❏

Why SQL?
SQL Syntax Introduction

Rundown
❏ SQL Practice
❏ Frequently Asked Questions
❏ Further Resources
Industry Overview Applied Examples FAQ’s Take Action!

The Data Ecosystem

Data Is Created Data Analysts


Interactions with a
product, service, or identify patterns in
the internet by user. Stakeholders
large volumes of data
request info or have
and report insights
questions they want
answered
Data Engineers
gather, store, Executives, Board Data Scientists
and structure Members, Managers specialize in
incoming data algorithms and
predictive modeling
Industry Overview Applied Examples FAQ’s Take Action!

Skillset
Spreadsheets

Basic Critical
Programming Thinking
and Stats

Data Analyst

Business Intel
SQL
Tools

Presentation
&
Communication
Industry Overview Applied Examples FAQ’s Take Action!

What Is SQL?
❏ Structured Query Language
❏ Usually pronounced like the
word “sequel”
❏ Communicates with databases
to manage data
Industry Overview Applied Examples FAQ’s Take Action!

Who Uses SQL?

Used Across The Board


❏ Fortune 500 companies, small
businesses, online stores
❏ Data analytics, data science,
web and app development
Industry Overview Applied Examples FAQ’s Take Action!

Database Systems

Program that allows business to work with database


via user interface
❏ Oracle DB - online transaction processing
❏ MySQL - free, popular with small businesses
❏ Microsoft SQL Server - Windows-based
❏ PostgreSQL - free, popular with tech startups
Industry Overview Applied Examples FAQ’s Take Action!

SQL Syntax
Industry Overview Applied Examples FAQ’s Take Action!

Database Setup
SQL Schema SQL Playground

❏ Open the SQL Schema file


❏ Select All (Control + A), and
copy it (Control + C)
❏ Open the SQL Playground link - DB Fiddle
❏ Change the Database dropdown to: PostgreSQL v9.6
❏ Paste (Control + V) the SQL schema into the
left-hand side of the Playground (Schema SQL)
Industry Overview Applied Examples FAQ’s Take Action!

Database Databases are typically arranged in tables

Tables ➔ Columns and rows represent data

rows
books

id title author year

1 Harry Potter and the Half-Blood Prince J. K. Rowling 2005


columns

2 Pride and Prejudice Jane Austen 1813

3 The Da Vinci Code Dan Brown 2003


Industry Overview Applied Examples FAQ’s Take Action!

SQL Statements: Most common SQL command

SELECT FROM ➔ Retrieves data from a table


➔ We specify column(s) to include

Syntax: Example:
SELECT column_list SELECT title, year
FROM table_name FROM books
Industry Overview Applied Examples FAQ’s Take Action!

SQL Statements: Example:

SELECT FROM SELECT title, year


FROM books

books

id title author year

1 Harry Potter and the Half-Blood Prince J. K. Rowling 2005

2 Pride and Prejudice Jane Austen 1813

3 The Da Vinci Code Dan Brown 2003


Industry Overview Applied Examples FAQ’s Take Action!

SQL Statements: Example:

SELECT FROM SELECT title, year


FROM books

result

title year

Harry Potter and the Half-Blood Prince 2005

Pride and Prejudice 1813

The Da Vinci Code 2003


Industry Overview Applied Examples FAQ’s Take Action!

SQL Statements:
WHERE
Syntax:
Filters relevant results
SELECT column_list
➔ Returns only results that FROM table_name
meet the condition WHERE condition
Industry Overview Applied Examples FAQ’s Take Action!

SQL Statements: Example:

WHERE SELECT *
FROM books

books WHERE year > 2000

id title author year

1 Harry Potter and the Half-Blood Prince J. K. Rowling 2005

2 Pride and Prejudice Jane Austen 1813

3 The Da Vinci Code Dan Brown 2003


Industry Overview Applied Examples FAQ’s Take Action!

SQL Statements: Example:

WHERE SELECT *
FROM books
WHERE year > 2000

result

id title author year

1 Harry Potter and the Half-Blood Prince J. K. Rowling 2005

3 The Da Vinci Code Dan Brown 2003


Industry Overview Applied Examples FAQ’s Take Action!

SQL Statements:
AND/OR/NOT
Used with WHERE clause to filter
based on multiple conditions Syntax:

➔ AND displays ALL that are true SELECT column_list

➔ OR displays ANY that are true FROM table_name

➔ NOT displays ALL that are NOT WHERE condition1 OR condition2 OR condition3

true
Industry Overview Applied Examples FAQ’s Take Action!

SQL Statements: Example:

AND/OR/NOT SELECT title, author


FROM books
WHERE year > 2000 AND year < 2004

id title author year

1 Harry Potter and the Half-Blood Prince J. K. Rowling 2005

2 Pride and Prejudice Jane Austen 1813

3 The Da Vinci Code Dan Brown 2003


Industry Overview Applied Examples FAQ’s Take Action!

SQL Statements: Example:

AND/OR/NOT SELECT title, author


FROM books
WHERE year > 2000 AND year < 2004

result

title author

The Da Vinci Code Dan Brown


Industry Overview Applied Examples FAQ’s Take Action!

SQL Statements:
GROUP BY
Syntax:

Groups database records and SELECT column_list

aggregates information, i.e.: FROM table_name

➔ Average (AVG) GROUP BY column1,column2

➔ Maximum (MAX)
Industry Overview Applied Examples FAQ’s Take Action!

SQL Statements: Example:


SELECT genre, AVG(year) AS avg_year
GROUP BY FROM books
GROUP BY genre
books
result
id title year genre sub_genre
genre avg_year
1 Harry Potter and the Half-Blood Prince 2005 fiction fantasy
fiction 1974.571
2 Pride and Prejudice 1813 fiction novel
non-fiction 1958.125
3 The Da Vinci Code 2003 fiction mystery
Industry Overview Applied Examples FAQ’s Take Action!

SQL Statements:
ORDER BY

Syntax:
Sorts the result set
SELECT column_list
➔ Ascending (default) FROM table_name
➔ Descending (DESC) ORDER BY column1, column2 ASC|DESC
Industry Overview Applied Examples FAQ’s Take Action!

SQL Statements: Example:

ORDER BY SELECT *
FROM books
result
books ORDER BY year DESC

book_id
id title
title author
author year
year

1 HarryPotter
Harry Potterandand
the the Half-Blood
Half-Blood Prince Prince J. K.
J. K.Rowling
Rowling 2005
2005

3
2 The Da
Pride andVinci Code
Prejudice Dan Brown
Jane Austen 2003
1813

2
3 Pride
The and Prejudice
Da Vinci Code JaneBrown
Dan Austen 1813
2003
Industry Overview Applied Examples FAQ’s Take Action!

Relational Tables
➔ Tables in the database are related based on unique keys

books
reviews
id title author
book_id average_rating
1 Harry Potter and the J. K. Rowling
Half-Blood Prince 1 4.7

2 Pride and Prejudice Jane Austen 2 4.5

3 The Da Vinci Code Dan Brown 3 4.5


Industry Overview Applied Examples FAQ’s Take Action!

SQL Statements: ➔ Combines data from two


JOIN ON tables based on unique key

Syntax:
SELECT column_list
FROM table_name
JOIN second_table ON table_name.key_column = second_table.key_column
Industry Overview Applied Examples FAQ’s Take Action!

Example:
SQL Statements: SELECT b.title, r.average_rating

JOIN ON FROM books AS b


JOIN reviews AS r ON b.id = r.book_id
books
reviews
id title author year
book_id average_rating

1 Harry Potter and the J. K. Rowling 2005


1 4.7
Half-Blood Prince

2 4.5
2 Pride and Prejudice Jane Austen 1813
3 4.5
3 The Da Vinci Code Dan Brown 2003
Industry Overview Applied Examples FAQ’s Take Action!

SQL Statements: Example:


SELECT b.title, r.average_rating
JOIN ON FROM books AS b
JOIN reviews AS r ON b.id = r.book_id
result

title average_rating

Harry Potter and the Half-Blood 4.7


Prince

Pride and Prejudice 4.5

The Da Vinci Code 4.5


Industry Overview Applied Examples FAQ’s Take Action!

Real Analysts Use Google... A Lot!


Industry Overview Applied Examples FAQ’s Take Action!

SQL Challenge!
Industry Overview Applied Examples FAQ’s Take Action!

Bikeshare Challenge

❏ You are a part of a team analyzing bikeshare usage in the Bay Area.
❏ Data on stations, trips taken, and the weather at those stations have
been compiled.
❏ Your task: Use data to answer questions to better understand
bikeshare usage
Industry Overview Applied Examples FAQ’s Take Action!

Challenge: Database Setup


SQL Schema SQL Playground

❏ Open the SQL Schema file


❏ Select All (Control + A), and
copy it (Control + C)
❏ Open the SQL Playground link - DB Fiddle
❏ Change the Database dropdown to: PostgreSQL v9.6
❏ Paste (Control + V) the SQL schema into the
left-hand side of the Playground (Schema SQL)
Industry Overview Applied Examples FAQ’s Take Action!

Table Name: weather


Table Name: trips

Challenge:
date
trip_id
*temperature_f

Database duration

start_date
*dew_point

Structure start_station
*humidity

*sea_level_pressureIn
Table Name: stations start_terminal
*visibility
name end_date
*wind_speed_mph
lat end_station
precipitation_in
long end_terminal
cloud_cover
dockcount bike_id
events
city subscriber_type
wind_dir_degrees
installation zip_code
zip
“*” indicates that there are columns for min, mean, and max values for this indicator
Industry Overview Applied Examples FAQ’s Take Action!

Challenge Level:
Beach Cruising

Write SQL queries to pull the following information:


❏ List all of the station names alphabetically
❏ Find all of the ids and durations of trips with a duration longer
than 500 minutes ordered by decreasing duration
❏ Identify all of the trips that the bike with bike_id 450 completed,
listing start_dates and start_stations in ascending order
Industry Overview Applied Examples FAQ’s Take Action!

Challenge Level:
Road Race
Write SQL queries to pull the following information:
❏ What is the average number of docks at all stations?
❏ Which zip code has the highest average maximum precipitation?
❏ Which station was the most popular destination? How many trips
ended at this station?
❏ For each starting station, list the average trip duration by
descending duration (BONUS: add the city)
Industry Overview Applied Examples FAQ’s Take Action!

Challenge Level:
Tour de France

Write SQL queries to pull the following information:


❏ Find the average temperature and average rainfall of the three
most popular cities for all “Subscribers”
❏ What were the five longest trips on rainy days?
Industry Overview Applied Examples FAQ’s Take Action!

Challenge Answers

Use the link below to check your work


after you’ve attempted the challenges.
Solutions to SQL Challenges
Industry Overview Applied Examples FAQ’s Take Action!

?
Common Questions

You might also be wondering


❏ What are the outcomes of your students
for this field?
❏ How do I show my work to a potential
employer?
❏ Is this course entirely online?
❏ What should I do from here?
Industry Overview Applied Examples FAQ’s Take Action!

Take the First Step


to A New Career
Anyone who’s driven to change their future and achieve a
high-earning career is able to enter the world’s next
workforce. We’ll be by your side as you build the skills
you need, with personal mentorship and an active, online
community of students and educators.

Expand your career opportunities by breaking into tech.


Chat with an admissions rep and we’ll help you find the
perfect fit.

Schedule a Call

You might also like