Search icon CANCEL
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 – Linux

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

  1. Switch to the postgres user by typing the following command in the terminal. Press the return key to execute it:
    sudo su postgres

You should see your shell change as follows:

Figure 0.26: Loading the sample datasets on Linux

Figure 0.26: Loading the sample datasets on Linux

  1. Type or paste the following command to create a new database called sqlda. Press the return key to execute it:
    createdb sqlda

You can then type the psql command to enter the PostgreSQL shell, followed by \l (a backslash followed by lowercase L) to check if the database was successfully created:

Figure 0.27: Accessing the PostgreSQL shell on Linux

Figure 0.27: Accessing the PostgreSQL shell on Linux

Enter \q and then press the return key to quit the PostgreSQL shell.

  1. Download the data.dump file from the Datasets folder in the GitHub repository of this book by running this command:
    wget "https://github.com/PacktPublishing/SQL-for-Data-Analytics-Third-Edition/tree/main/Datasets/data.dump"
  2. Navigate to the folder where you have downloaded the file using the cd command. Then, type the following command:
    psql -d sqlda < data.dump
  3. Then, wait for the dataset to be imported:
Figure 0.28: Importing the dataset on Linux

Figure 0.28: Importing the dataset on Linux

  1. To test whether the dataset was imported correctly, type ppsql postgres and then press the return key to enter the PostgreSQL shell. Then, run \c sqlda followed by \dt to see the list of tables within the database:
Figure 0.29: Validating the import on Linux

Figure 0.29: Validating the import on Linux

Note

You are importing the database using the postgres superuser for demonstration purposes only. It is advised in production environments to use a separate account.

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 £16.99/month. Cancel anytime