Practical SQL: A Beginner's Guide to Storytelling with Data
Book information
Description
Practical SQL is an approachable and fast-paced guide to SQL (Structured Query Language), the standard programming language for defining, organizing, and exploring data in relational databases. The book focuses on using SQL to find the story your data tells, with the popular open-source database PostgreSQL and the pgAdmin interface as its primary tools. You’ll first cover the fundamentals of databases and the SQL language, then build skills by analyzing data from the U.S. Census and other federal and state government agencies. With exercises and real-world examples in each chapter, this book will teach even those who have never programmed before all the tools necessary to build powerful databases and access information quickly and efficiently. You’ll learn how to: - Create databases and related tables using your own data - Define the right data types for your information - Aggregate, sort, and filter data to find patterns - Use basic math and advanced statistical functions - Identify errors in data and clean them up - Import and export data using delimited text files - Write queries for geographic information systems (GIS) - Create advanced queries and automate tasks Learning SQL doesn’t have to be dry and complicated. Practical SQL delivers clear examples with an easy-to-follow approach to teach you the tools you need to build and manage your own databases. This book uses PostgreSQL, but the SQL syntax is applicable to many database applications, including Microsoft SQL Server and MySQL. Title Page Copyright Page About the Author About the Technical Reviewer Brief Contents Contents in Detail Foreword by Sarah Frostenson Acknowledgments Introduction What Is SQL? Why Use SQL? About This Book Using the Book’s Code Examples Using PostgreSQL Wrapping Up 1. Creating Your First Database and Table Creating a Database Creating a Table Inserting Rows into a Table When Code Goes Bad Formatting SQL for Readability Wrapping Up Try It Yourself 2. Beginning Data Exploration with SELECT Basic SELECT Syntax Sorting Data with ORDER BY Filtering Rows with WHERE Putting It All Together Wrapping Up Try It Yourself 3. Understanding Data Types Characters Numbers Dates and Times Using the interval Data Type in Calculations Miscellaneous Types Transforming Values from One Type to Another with CAST CAST Shortcut Notation Wrapping Up Try It Yourself 4. Importing and Exporting Data Working with Delimited Text Files Using COPY to Import Data Importing Census Data Describing Counties Importing a Subset of Columns with COPY Adding a Default Value to a Column During Import Using COPY to Export Data Importing and Exporting Through pgAdmin Wrapping Up Try It Yourself 5. Basic Math and Stats With SQL Math Operators Doing Math Across Census Table Columns Aggregate Functions for Averages and Sums Finding the Median Finding the Mode Wrapping Up Try It Yourself 6. Joining Tables in a Relational Database Linking Tables Using JOIN Relating Tables with Key Columns Querying Multiple Tables Using JOIN JOIN Types Using NULL to Find Rows with Missing Values Three Types of Table Relationships Selecting Specific Columns in a Join Simplifying JOIN Syntax with Table Aliases Joining Multiple Tables Performing Math on Joined Table Columns Wrapping Up Try It Yourself 7. Table Design That Works for You Naming Tables, Columns, and Other Identifiers Controlling Column Values with Constraints Speeding Up Queries with Indexes Wrapping Up Try It Yourself 8. Extracting Information by Grouping and Summarizing Creating the Library Survey Tables Exploring the Library Data Using Aggregate Functions Wrapping Up Try It Yourself 9. Inspecting and Modifying Data Importing Data on Meat, Poultry, and Egg Producers Interviewing the Data Set Modifying Tables, Columns, and Data Deleting Unnecessary Data Using Transaction Blocks to Save or Revert Changes Improving Performance When Updating Large Tables Wrapping Up Try It Yourself 10. Statistical Functions in SQL Creating a Census Stats Table Creating Rankings with SQL Calculating Rates for Meaningful Comparisons Wrapping Up Try It Yourself 11. Working with Dates and Times Data Types and Functions for Dates and Times Manipulating Dates and Times Working with Time Zones Calculations with Dates and Times Wrapping Up Try It Yourself 12. Advanced Query Techniques Using Subqueries Common Table Expressions Cross Tabulations Reclassifying Values with CASE Using CASE in a Common Table Expression Wrapping Up Try It Yourself 13. Mining Text to Find Meaningful Data Formatting Text Using String Functions Matching Text Patterns with Regular Expressions Full Text Search in PostgreSQL Wrapping Up Try It Yourself 14. Analyzing Spatial Data with PostGIS Installing PostGIS and Creating a Spatial Database The Building Blocks of Spatial Data Two-Dimensional Geometries PostGIS Data Types Creating Spatial Objects with PostGIS Functions Analyzing Farmers’ Markets Data Working with Census Shapefiles Performing Spatial Joins Wrapping Up Try It Yourself 15. Saving Time with Views, Functions, and Triggers Using Views to Simplify Queries Programming Your Own Functions Automating Database Actions with Triggers Wrapping Up Try It Yourself 16. Using PostgreSQL from the Command Line Setting Up the Command Line for psql Working with psql Additional Command Line Utilities to Expedite Tasks Wrapping Up Try It Yourself 17. Maintaining Your Database Recovering Unused Space with VACUUM Changing Server Settings Backing Up and Restoring Your Database Wrapping Up Try It Yourself 18. Identifying and Telling the Story Behind Your Data Start with a Question Document Your Process Gather Your Data No Data? Build Your Own Database Assess the Data’s Origins Interview the Data with Queries Consult the Data’s Owner Identify Key Indicators and Trends over Time Ask Why Communicate Your Findings Wrapping Up Try It Yourself Appendix: Additional PostgreSQL Resources PostgreSQL Development Environments PostgreSQL Utilities, Tools, and Extensions PostgreSQL News Documentation Index
Similar books
Practical SQL, 2nd Edition: A Beginner's Guide to Storytelling with Data
2022 · PDF
Practical SQL: A Beginner's Guide to Storytelling with Data, 2nd Edition
2022 · EPUB
Practical SQL, 2nd Edition: A Beginner's Guide to Storytelling with Data
2022 · EPUB
Practical SQL: A Beginner's Guide to Storytelling with Data
2018 · PDF
Practical SQL: A Beginner's Guide to Storytelling with Data
2018 · PDF
Practical SQL: A Beginner's Guide to Storytelling with Data
2018 · EPUB
Practical SQL: A Beginner’s Guide to Storytelling with Data
2018 · PDF
Practical SQL: A Beginner’s Guide to Storytelling with Data
2018 · EPUB