Malik U. SQL for Data Analytics...2019.pdf

(11973 KB) Pobierz
SQL for Data Analytics
Perform fast and efficient data analysis with the
power of SQL
Upom Malik
Matt Goldwasser
Benjamin Johnston
SQL for Data Analytics
Copyright © 2019 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system,
or transmitted in any form or by any means, without the prior written permission of the
publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of
the information presented. However, the information contained in this book is sold
without warranty, either express or implied. Neither the authors, nor Packt Publishing,
and its dealers and distributors will be held liable for any damages caused or alleged to
be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
Authors: Upom Malik, Matt Goldwasser, and Benjamin Johnston
Technical Reviewer: Halil Burak Cetinkaya
Managing Editor: Aditya Shah
Acquisitions Editor: Aditya Date
Production Editor: Shantanu Zagade
Editorial Board: Shubhopriya Banerjee, Mayank Bhardwaj, Ewan Buckingham, Mahesh
Dhyani, Taabish Khan, Manasa Kumar, Alex Mazonowicz, Pramod Menon, Bridget
Neale, Dominic Pereira, Shiny Poojary, Erol Staveley, Ankita Thakur, Nitesh Thakur, and
Jonathan Wray
First Published: August 2019
Production Reference: 1220819
ISBN: 978-1-78980-735-6
Published by Packt Publishing Ltd.
Livery Place, 35 Livery Street
Birmingham B3 2PB, UK
Table of Contents
Preface
Understanding and Describing Data
i
1
Introduction
.................................................................................................... 2
The World of Data .......................................................................................... 2
Types of Data
........................................................................................................ 2
Data Analytics and Statistics
.............................................................................. 3
Types of Statistics
................................................................................................ 4
Activity 1: Classifying a New Dataset
................................................................. 5
Methods of Descriptive Statistics
................................................................ 6
Univariate Analysis
.............................................................................................. 6
Data Frequency Distribution
.............................................................................. 6
Exercise 1: Creating a Histogram
....................................................................... 7
Exercise 2: Calculating the Quartiles for Add-on Sales
.................................
13
Central Tendency
...............................................................................................
16
Exercise 3: Calculating the Central Tendency of Add-on Sales
....................
17
Dispersion ...........................................................................................................
19
Exercise 4: Dispersion of Add-on Sales
............................................................ 20
Bivariate Analysis
...............................................................................................
21
Scatterplots
........................................................................................................
21
Exercise 5: Calculating the Pearson Correlation Coefficient
for Two Variables ...............................................................................................
29
Activity 2: Exploring Dealership Sales Data
.................................................... 36
Working with Missing Data ............................................................................... 36
Statistical Significance Testing
................................................................... 37
Common Statistical Significance Tests
............................................................
39
Summary
.......................................................................................................
39
The Basics of SQL for Analytics
43
Introduction
.................................................................................................. 44
Relational Databases and SQL ................................................................... 44
Advantages and Disadvantages of SQL Databases
....................................... 45
Basic Data Types of SQL
.............................................................................. 47
Numeric
............................................................................................................... 47
Character
............................................................................................................ 48
Boolean ............................................................................................................... 48
Datetime .............................................................................................................
49
Data Structures: JSON and Arrays
...................................................................
49
Reading Tables: The SELECT Query
............................................................ 50
Basic Anatomy and Working of a SELECT Query
............................................ 50
Basic Keywords in a SELECT Query
..................................................................
51
Exercise 6: Querying the Salespeople Table Using
Basic Keywords in a SELECT Query
.................................................................. 57
Activity 3: Querying the customers Table Using Basic Keywords
in a SELECT Query
..............................................................................................
59
Creating Tables ............................................................................................ 60
Creating Blank Tables ........................................................................................ 60
Exercise 7: Creating a Table in SQL
..................................................................
61
Creating Tables with SELECT ............................................................................. 62
Updating Tables ........................................................................................... 62
Adding and Removing Columns
....................................................................... 62
Zgłoś jeśli naruszono regulamin