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
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 – Windows

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. First, create a database titled sqlda. Open the command line and type or paste the following command. Then, press the return key to execute it:
    createdb -U postgres sqlda

You will be prompted to enter the password that you set for the postgres superuser during installation:

Figure 0.22: PostgreSQL shell password request

Figure 0.22: PostgreSQL shell password request

  1. To check whether the database has been successfully created, log in to the shell by typing or pasting the following command and pressing the return key:
    psql -U postgres

Enter your password when prompted. Press the return key to proceed.

  1. Type \l (a backslash and a lowercase L) and then press the return key to check if the database has been created. The sqlda database should appear along with a list of the default databases:
Figure 0.23: PostgreSQL list of databases

Figure 0.23: PostgreSQL list of databases

  1. Download the data.dump file from the Datasets folder in the GitHub repository of this book by clicking this link: http://packt.link/GuU31. Modify the highlighted path in the following command based on where the file is located on your system. Type or paste the command into the command line and press the return key to execute it:
    psql -U postgres -d sqlda -f C:\<path>\data.dump

    Note

    Alternatively, you can use the command line and navigate to the local folder where you have downloaded the file using the cd command. For example, if you have downloaded it to the Downloads folders of your computer, you can navigate to it using cd C:\Users\<your username>\Downloads. In this case, remove the highlighted path prefix in the step. The command should look like this: psql -U postgres -d sqlda -f data.dump.

You should get an output similar to the one that follows:

Figure 0.24: PostgreSQL database import

Figure 0.24: PostgreSQL database import

  1. Check whether the database has been loaded correctly. Log in to the PostgreSQL console by typing or pasting the following command. Press the return key to execute it:
    psql –U postgres

In the shell, type the following command to connect to the sqlda database:

\c sqlda

Then type \dt. This command should list all the tables in the database, as follows:

Figure 0.25: Validating that the database has been imported

Figure 0.25: Validating that the database has been imported

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 $19.99/month. Cancel anytime
Banner background image