sql tutorial for marketers

51
SQL for Marketers and Growth Hackers Everything you need to know about using SQL for analytics, marketing and growth hacking

Upload: justin-mares

Post on 21-Jan-2018

10.958 views

Category:

Data & Analytics


1 download

TRANSCRIPT

Page 1: SQL Tutorial for Marketers

SQL for Marketers and Growth Hackers

Everything you need to know about using SQL for analytics, marketing and growth

hacking

Page 2: SQL Tutorial for Marketers

What is SQL?

SQL is simply a language that makes it easy to pull data from your application’s database.

Page 3: SQL Tutorial for Marketers

What can you do with SQL?

Answer questions!

Page 4: SQL Tutorial for Marketers

Life without SQL

Without SQL…. •  You annoy technical people on your

team

•  Hack together rough approximations for hours

Page 5: SQL Tutorial for Marketers

Life with SQL

“Starting in 2013, after the CMO realizes that he/she does not have the skill sets in place for data analytics proficiency, 50% of new marketing hires will have technical backgrounds.” - quote from IDC research of CMOs

Page 6: SQL Tutorial for Marketers

Why is SQL important to me?

SQL will help you see, understand and improve your company’s metrics.

Page 7: SQL Tutorial for Marketers

Why is SQL important to me?

SQL will help you see, understand and improve your company’s metrics. It allows you to access data other analytics tools cannot (Kissmetrics, Mixpanel, Google Analytics, etc.)

Page 8: SQL Tutorial for Marketers

Do you know the answers to some very basic questions about your business?

Take a Minute

Page 9: SQL Tutorial for Marketers

Do you know the answers to some very basic questions about your business? – Are you getting more customers or less this

month compared to previous?

Take a Minute

Page 10: SQL Tutorial for Marketers

Do you know the answers to some very basic questions about your business? – Are you getting more customers or less this

month compared to previous? – What percentage of customers are active

every week on your platform?

Take a Minute

Page 11: SQL Tutorial for Marketers

Do you know the answers to some very basic questions about your business? – Are you getting more customers or less this

month compared to previous? – What percentage of customers are active

every week on your platform? – How many users leave each week (churn)?

Is this trending up or down?

Take a Minute

Page 12: SQL Tutorial for Marketers

Do you know the answers to some very basic questions about your business? – Are you getting more customers or less this

month compared to previous? – What percentage of customers are active

every week on your platform? – How many users leave each week (churn)?

Is this trending up or down? – Who are your 100 most active users? Who

are your 100 most valuable customers?

Take a Minute

Page 13: SQL Tutorial for Marketers

What can you do with SQL?

•  Make data-driven decisions

•  Run profitable campaigns using data

•  Understand every metric in your business

•  Get superpowers

Page 14: SQL Tutorial for Marketers

How we improved churn with the help of SQL

Page 15: SQL Tutorial for Marketers

Early Win for You!

Let’s take a second and have you do 2 things to get the most from this course: 1.  Get read-only access to your database

Page 16: SQL Tutorial for Marketers

Early Win for You!

Let’s take a second and have you do 2 things to get the most from this course: 1.  Get read-only access to your database

2.  Ask someone technical how to run queries against this database

Page 17: SQL Tutorial for Marketers

A WORD OF CAUTION

Only run queries on a read-only or “slave” database

Page 18: SQL Tutorial for Marketers

How SQL Works A database works a lot like an Excel spreadsheet. It will contain multiple tables – all with unique names, like “Customers” – with each table containing rows and columns

Page 19: SQL Tutorial for Marketers

Why SQL is Better than Excel •  Auto-updating information

•  Easier to query

•  Can visualize data automatically

Page 20: SQL Tutorial for Marketers

Example Query

*See  how  this  query  works  by  checking  out  the  example  database  I  pulled  together  at  -­‐  h"p://bitly.com/udemysql  

Page 21: SQL Tutorial for Marketers

Example Query

*See  how  this  query  works  by  checking  out  the  example  database  I  pulled  together  at  -­‐  h"p://bitly.com/udemysql  

Page 22: SQL Tutorial for Marketers

SQL Queries Select — This command tells SQL what data you want to see. This data needs to be a part of the table you’re accessing.

Page 23: SQL Tutorial for Marketers

SQL Queries From — this command tells SQL where to pull the data from. What’s the name of the table you’re using to capture data? Put that after the “from” statement.

Page 24: SQL Tutorial for Marketers

SQL Queries Join — This command temporarily joins two tables we’d like to search, so that we can pull data from multiple queries. “Join” tells SQL which table we’d like to join, and the “on” modifier tells SQL which columns in those tables should map to each other.

Page 25: SQL Tutorial for Marketers

SQL Queries Where — This statement tells SQL how to access the right data. In this case, we’re telling it to show us users who have gotten errors in production AND who have signed up within a certain time period.

Page 26: SQL Tutorial for Marketers

SQL Queries Group by – This statement tells SQL how to group your data when it returns the query result. In this case, data will be grouped by name in the ‘users’ table. Think of this as a massive sort function in Excel.

Page 27: SQL Tutorial for Marketers

SQL Queries Order by – This statement tells SQL how to order your data. This can be useful when pulling massive amounts of information from the database.

Page 28: SQL Tutorial for Marketers

SQL Queries Limit – This tells SQL how much data to return. In our case, we’ll only receive the first 15 results that fit the results of this query.

Page 29: SQL Tutorial for Marketers

SQL Queries Functions •  Avg() – returns the average value

Page 30: SQL Tutorial for Marketers

SQL Queries Functions •  Avg() – returns the average value •  Count() – returns the number of rows

Page 31: SQL Tutorial for Marketers

SQL Queries Functions •  Avg() – returns the average value •  Count() – returns the number of rows •  First() – returns the first value of a

column or row

Page 32: SQL Tutorial for Marketers

SQL Queries Functions •  Avg() – returns the average value •  Count() – returns the number of rows •  First() – returns the first value of a

column or row •  Last() – returns the last value

Page 33: SQL Tutorial for Marketers

SQL Queries Functions •  Avg() – returns the average value •  Count() – returns the number of rows •  First() – returns the first value of a

column or row •  Last() – returns the last value •  Max() – returns the largest value

Page 34: SQL Tutorial for Marketers

SQL Queries Functions •  Avg() – returns the average value •  Count() – returns the number of rows •  First() – returns the first value of a

column or row •  Last() – returns the last value •  Max() – returns the largest value •  Min() – returns the smallest value

Page 35: SQL Tutorial for Marketers

SQL Queries Functions •  Avg() – returns the average value •  Count() – returns the number of rows •  First() – returns the first value of a

column or row •  Last() – returns the last value •  Max() – returns the largest value •  Min() – returns the smallest value •  Sum() – returns the sum

Page 36: SQL Tutorial for Marketers

You know SQL!

Page 37: SQL Tutorial for Marketers

Where to Write Queries?

Depends on your stack:

Page 38: SQL Tutorial for Marketers

Where to Write Queries?

Depends on your stack: •  phpMyAdmin

Page 39: SQL Tutorial for Marketers

Where to Write Queries?

Depends on your stack: •  phpMyAdmin •  Heroku Postgres Dataclips

Page 40: SQL Tutorial for Marketers

Where to Write Queries?

Depends on your stack: •  phpMyAdmin •  Heroku Postgres Dataclips

Page 41: SQL Tutorial for Marketers

Where to Write Queries?

Depends on your stack: •  phpMyAdmin •  Heroku Postgres Dataclips •  Eclipse SQL Explorer

Page 42: SQL Tutorial for Marketers

Where to Write Queries?

Depends on your stack: •  phpMyAdmin •  Heroku Postgres Dataclips •  Eclipse SQL Explorer •  SQuirreL

Page 43: SQL Tutorial for Marketers

Where to Write Queries?

Depends on your stack: •  phpMyAdmin •  Heroku Postgres Dataclips •  Eclipse SQL Explorer •  SQuirreL •  Oracle SQL Developer

Page 44: SQL Tutorial for Marketers

Finding Table and Column Names Connect to the database: •  mysql  [-­‐u  username]  [-­‐h  hostname]  database-­‐name  

List all databases (type into MySQL prompt): •  show  databases    Choose the database you want: •  use  <database-­‐name>  

List all tables in the database: •  show  tables  

Describe a table: •  describe  <table-­‐name>  

Page 45: SQL Tutorial for Marketers

Example: Finding repeat buyers

Test SQL Database - http://www.w3schools.com/sql/trysql.asp?filename=trysql_select_all

STOP

How would you construct this query? Try writing it in on your own now.

Page 46: SQL Tutorial for Marketers

Example: Finding repeat buyers

   

Page 47: SQL Tutorial for Marketers

Understand Your User Demographics

Let’s say you want to answer the question “what countries are most of my users from?” Write a query that pulls that information from the test W3schools database.

Page 48: SQL Tutorial for Marketers

Answer: Understand Your User Demographics

   

Page 49: SQL Tutorial for Marketers

Cohort Analysis

See how groups of customers use your product

Page 50: SQL Tutorial for Marketers

Cohort Analysis

Cohort analysis leads to interesting, actionable data like the below

Page 51: SQL Tutorial for Marketers

Closing

That’s it!

Get the SQL creator spreadsheet, downloadable queries and additional

resources at justinmares.com/sql