Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
SQL for Data Analytics

You're reading from   SQL for Data Analytics Harness the power of SQL to extract insights from data

Arrow left icon
Product type Paperback
Published in Aug 2022
Publisher Packt
ISBN-13 9781801812870
Length 540 pages
Edition 3rd Edition
Languages
Arrow right icon
Authors (4):
Arrow left icon
Benjamin Johnston Benjamin Johnston
Author Profile Icon Benjamin Johnston
Benjamin Johnston
Matt Goldwasser Matt Goldwasser
Author Profile Icon Matt Goldwasser
Matt Goldwasser
Jun Shan Jun Shan
Author Profile Icon Jun Shan
Jun Shan
Upom Malik Upom Malik
Author Profile Icon Upom Malik
Upom Malik
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Understanding and Describing Data 2. The Basics of SQL for Analytics FREE CHAPTER 3. SQL for Data Preparation 4. Aggregate Functions for Data Analysis 5. Window Functions for Data Analysis 6. Importing and Exporting Data 7. Analytics Using Complex Data Types 8. Performant SQL 9. Using SQL to Uncover the Truth: A Case Study Appendix

Loading the Sample Datasets – macOS

Most exercises in this book use a sample database, sqlda, which contains fabricated data for a fictional electric vehicle company called ZoomZoom. Now, set it up by performing the following steps:

  1. Enter the PostgreSQL shell by typing the following command in Terminal. Press the return key to execute it:
    psql postgres
  2. Now, create a new database called sqlda by typing the following command and pressing return (do not forget the semicolon at the end):
    create database sqlda;
  3. You should see the following output. Type \l (a backslash followed by lowercase L) in Terminal and press the return key to check whether the database was successfully created (you should see the sqlda database listed there):
Figure 0.30: Checking whether a new database is successfully created

Figure 0.30: Checking whether a new database is successfully created

  1. Type or paste \q in the PostgreSQL shell and press the return key to exit.
  2. Download the data.dump file from the Datasets folder in the GitHub repository of this book at https://packt.link/GuU31. Navigate to the folder where you have downloaded the file using the cd command. Then, type the following command:
    psql sqlda < ~/Downloads/data.dump

    Note

    The preceding command assumes that the file is saved in the Downloads directory. Make sure you change the highlighted path based on the location of the data.dump file on your system.

  3. Then, wait for the dataset to be imported:
Figure 0.31: Importing the dataset

Figure 0.31: Importing the dataset

  1. To test if the dataset was imported correctly, type psql postgres and then press the return key to enter the PostgreSQL shell again. Then, run \c sqlda followed by \dt to see the list of tables within the database:
Figure 0.32: List of tables within the sqlda database

Figure 0.32: List of tables within the sqlda database

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image