├── Chapter01 ├── B19406_Chapter01.txt └── Chapter 1 dataset.xlsx ├── Chapter02 ├── B19406_Chapter02 .txt └── Chapter 2 _Dataset.xlsx ├── Chapter03 ├── B19406_Chapter03.docx └── Chapter 3 _Dataset.xlsx ├── Chapter04 ├── B19406_Chapter04.txt └── Chapter 4 dataset.xlsx ├── Chapter05 ├── B19406_Chapter05.txt └── Chapter 5 dataset.xlsx ├── Chapter06 ├── B19406_Chapter06.txt └── Chapter 6 Dataset.xlsx ├── Chapter07 ├── B19406_Chapter07.docx └── Chapter 7 Dataset.xlsx ├── Chapter08 ├── B19406_Chapter08.txt └── Chapter 8 dataset.xlsx ├── Chapter09 ├── B19406_Chapter09.docx └── Chapter 9 _Dataset.xlsx ├── Chapter10 └── Chapter 10 dataset.xlsx ├── Chapter11 ├── B19406_Chapter11.txt └── Chapter 11 dataset.xlsx ├── Chapter12 ├── B19406_Chapter12.txt └── Chapter 12 dataset.xlsx ├── Chapter13 ├── B19406_Chapter13.txt └── Chapter 13 dataset.xlsx ├── LICENSE └── README.md /Chapter01/B19406_Chapter01.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter01/B19406_Chapter01.txt -------------------------------------------------------------------------------- /Chapter01/Chapter 1 dataset.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter01/Chapter 1 dataset.xlsx -------------------------------------------------------------------------------- /Chapter02/B19406_Chapter02 .txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter02/B19406_Chapter02 .txt -------------------------------------------------------------------------------- /Chapter02/Chapter 2 _Dataset.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter02/Chapter 2 _Dataset.xlsx -------------------------------------------------------------------------------- /Chapter03/B19406_Chapter03.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter03/B19406_Chapter03.docx -------------------------------------------------------------------------------- /Chapter03/Chapter 3 _Dataset.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter03/Chapter 3 _Dataset.xlsx -------------------------------------------------------------------------------- /Chapter04/B19406_Chapter04.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter04/B19406_Chapter04.txt -------------------------------------------------------------------------------- /Chapter04/Chapter 4 dataset.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter04/Chapter 4 dataset.xlsx -------------------------------------------------------------------------------- /Chapter05/B19406_Chapter05.txt: -------------------------------------------------------------------------------- 1 | Identifying Null/Missing Values 2 | SELECT COUNT(*) AS null_count FROM customers WHERE email IS NULL; 3 | NULL Values vs 0 4 | SELECT * FROM customers WHERE phone IS NULL; 5 | 6 | SELECT name, COALESCE(phone, 'N/A') AS phone FROM customers; 7 | IS NULL() and IS NOT NULL() - Case Scenario 8 | SELECT 9 | make, 10 | model, 11 | last_service, 12 | next_service 13 | FROM vehicles 14 | WHERE next_service IS NULL; 15 | 16 | SELECT 17 | make, 18 | model, 19 | last_service, 20 | next_service 21 | FROM vehicles 22 | WHERE next_service IS NOT NULL; 23 | IFNULL() 24 | SELECT IFNULL(name, 'N/A') FROM table_name; 25 | OR 26 | SELECT IFNULL(name, 0) FROM table_name; 27 | Case Scenario 28 | 29 | SELECT 30 | IFNULL(customer_id, 'anonymous') as customer, 31 | SUM(total) as total_sales 32 | FROM orders 33 | GROUP BY customer; 34 | 35 | SELECT 36 | IFNULL(age, 'unknown') as age, 37 | SUM(spending) as total_spending 38 | FROM customer 39 | GROUP BY age; 40 | COALESCE() 41 | COALESCE(expression1, expression2, ... expression_n); 42 | 43 | SELECT name, COALESCE(price, 0) AS price FROM orders; 44 | Result: 45 | This will result in 0 for missing values as we are using 0 where the price is null. 46 | Case Scenario 47 | SELECT name, COALESCE(email, phone) AS contact_method FROM customers; 48 | 49 | SELECT 50 | post, 51 | COALESCE(likes, 0) AS likes, 52 | COALESCE(shares, 0) AS shares 53 | FROM posts; 54 | IS NULL VS = NULL 55 | * Using "IS NULL" 56 | SELECT * FROM employees WHERE salary IS NULL; 57 | * Using "= NULL" 58 | SELECT * FROM employees WHERE salary = NULL; 59 | 60 | * Using "IS NULL" 61 | 62 | SELECT * FROM employees WHERE salary IS NULL; 63 | * Using "= NULL" 64 | SELECT * FROM employees WHERE salary = NULL; 65 | -------------------------------------------------------------------------------- /Chapter05/Chapter 5 dataset.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter05/Chapter 5 dataset.xlsx -------------------------------------------------------------------------------- /Chapter06/B19406_Chapter06.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter06/B19406_Chapter06.txt -------------------------------------------------------------------------------- /Chapter06/Chapter 6 Dataset.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter06/Chapter 6 Dataset.xlsx -------------------------------------------------------------------------------- /Chapter07/B19406_Chapter07.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter07/B19406_Chapter07.docx -------------------------------------------------------------------------------- /Chapter07/Chapter 7 Dataset.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter07/Chapter 7 Dataset.xlsx -------------------------------------------------------------------------------- /Chapter08/B19406_Chapter08.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter08/B19406_Chapter08.txt -------------------------------------------------------------------------------- /Chapter08/Chapter 8 dataset.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter08/Chapter 8 dataset.xlsx -------------------------------------------------------------------------------- /Chapter09/B19406_Chapter09.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter09/B19406_Chapter09.docx -------------------------------------------------------------------------------- /Chapter09/Chapter 9 _Dataset.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter09/Chapter 9 _Dataset.xlsx -------------------------------------------------------------------------------- /Chapter10/Chapter 10 dataset.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter10/Chapter 10 dataset.xlsx -------------------------------------------------------------------------------- /Chapter11/B19406_Chapter11.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter11/B19406_Chapter11.txt -------------------------------------------------------------------------------- /Chapter11/Chapter 11 dataset.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter11/Chapter 11 dataset.xlsx -------------------------------------------------------------------------------- /Chapter12/B19406_Chapter12.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter12/B19406_Chapter12.txt -------------------------------------------------------------------------------- /Chapter12/Chapter 12 dataset.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter12/Chapter 12 dataset.xlsx -------------------------------------------------------------------------------- /Chapter13/B19406_Chapter13.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter13/B19406_Chapter13.txt -------------------------------------------------------------------------------- /Chapter13/Chapter 13 dataset.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Wrangling-with-SQL/fb369910267b88edb25826cdf3a4c699d1454468/Chapter13/Chapter 13 dataset.xlsx -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |

[![Packt Sale](https://static.packt-cdn.com/assets/images/packt+events/Improve_UX.png)](https://packt.link/algotradingpython)

3 | 4 |

Machine Learning Summit 2025

5 | 6 | ## Machine Learning Summit 2025 7 | **Bridging Theory and Practice: ML Solutions for Today’s Challenges** 8 | 9 | 3 days, 20+ experts, and 25+ tech sessions and talks covering critical aspects of: 10 | - **Agentic and Generative AI** 11 | - **Applied Machine Learning in the Real World** 12 | - **ML Engineering and Optimization** 13 | 14 | 👉 [Book your ticket now >>](https://packt.link/mlsumgh) 15 | 16 | --- 17 | 18 | ## Join Our Newsletters 📬 19 | 20 | ### DataPro 21 | *The future of AI is unfolding. Don’t fall behind.* 22 | 23 |

DataPro QR

24 | 25 | Stay ahead with [**DataPro**](https://landing.packtpub.com/subscribe-datapronewsletter/?link_from_packtlink=yes), the free weekly newsletter for data scientists, AI/ML researchers, and data engineers. 26 | From trending tools like **PyTorch**, **scikit-learn**, **XGBoost**, and **BentoML** to hands-on insights on **database optimization** and real-world **ML workflows**, you’ll get what matters, fast. 27 | 28 | > Stay sharp with [DataPro](https://landing.packtpub.com/subscribe-datapronewsletter/?link_from_packtlink=yes). Join **115K+ data professionals** who never miss a beat. 29 | 30 | --- 31 | 32 | ### BIPro 33 | *Business runs on data. Make sure yours tells the right story.* 34 | 35 |

BIPro QR

36 | 37 | [**BIPro**](https://landing.packtpub.com/subscribe-bipro-newsletter/?link_from_packtlink=yes) is your free weekly newsletter for BI professionals, analysts, and data leaders. 38 | Get practical tips on **dashboarding**, **data visualization**, and **analytics strategy** with tools like **Power BI**, **Tableau**, **Looker**, **SQL**, and **dbt**. 39 | 40 | > Get smarter with [BIPro](https://landing.packtpub.com/subscribe-bipro-newsletter/?link_from_packtlink=yes). Trusted by **35K+ BI professionals**, see what you’re missing. 41 | 42 | 43 | ### [Packt Conference : Put Generative AI to work on Oct 11-13 (Virtual)](https://packt.link/JGIEY) 44 | 45 |

[![Packt Conference](https://hub.packtpub.com/wp-content/uploads/2023/08/put-generative-ai-to-work-packt.png)](https://packt.link/JGIEY)

46 | 3 Days, 20+ AI Experts, 25+ Workshops and Power Talks 47 | 48 | Code: USD75OFF 49 | 50 | # Data Wrangling with SQL 51 | 52 | Relational databases 53 | 54 | This is the code repository for [Data Wrangling with SQL](https://www.packtpub.com/product/data-wrangling-with-sql/9781837630028?utm_source=github&utm_medium=repository&utm_campaign=9781837630028), published by Packt. 55 | 56 | **A hands-on guide to manipulating, wrangling, and engineering 57 | data using SQL.** 58 | 59 | ## What is this book about? 60 | 61 | This book covers the following exciting features: 62 | Build time series models using data wrangling 63 | Discover data wrangling best practices as well as tips and tricks 64 | Find out how to use subqueries, window functions, CTEs, and aggregate functions 65 | Handle missing data, data types, date formats, and redundant data 66 | Build clean and efficient data models using data wrangling techniques 67 | Remove outliers and calculate standard deviation to gauge the skewness of data 68 | 69 | If you feel this book is for you, get your [copy](https://www.amazon.com/dp/183763002X) today! 70 | 71 | https://www.packtpub.com/ 73 | 74 | ## Instructions and Navigations 75 | All of the code is organized into folders. For example, Chapter01. 76 | 77 | The code will look like the following: 78 | ``` 79 | { 80 | Customer_ID int, 81 | Name varchar(255), 82 | Address varchar(255),Email varchar(255), 83 | Phone varchar(255) 84 | ) 85 | ``` 86 | 87 | **Following is what you need for this book:** 88 | This book is for SQL developers, data analysts, report writers, data scientists, and other data gatherers looking to expand their skills for complex querying as well as for building more efficient and performant queries. 89 | For those new to SQL, this book can help you accelerate your learning and keep you from making common mistakes. 90 | 91 | With the following software and hardware list you can run all code files present in the book (Chapter 1-13). 92 | ### Software and Hardware List 93 | | Chapter | Software required | OS required | 94 | | -------- | ------------------------------------ | ----------------------------------- | 95 | | 1-13 | SQL database | Windows or macOS | 96 | | 1-13 | MySQL | Windows or macOS | 97 | | 1-13 | SQL Server (for some examples) | Windows or macOS | 98 | 99 | ### Related products 100 | * SQL Query Design Patterns and Best Practices [[Packt]](https://www.packtpub.com/product/sql-query-design-patterns-and-best-practices/9781837633289?utm_source=github&utm_medium=repository&utm_campaign=9781837633289) [[Amazon]](https://www.amazon.com/dp/1837633282) 101 | 102 | * Data Ingestion with Python Cookbook [[Packt]](https://www.packtpub.com/product/data-ingestion-with-python-cookbook/9781837632602?utm_source=github&utm_medium=repository&utm_campaign=9781837632602) [[Amazon]](https://www.amazon.com/dp/183763260X) 103 | 104 | 105 | 106 | ## Get to Know the Authors 107 | **Raghav Kandarpa,** 108 | is a skilled author and data analyst passionate about extracting insights from complex 109 | datasets. Originally from India, he pursued his academic and professional goals in data analysis in the 110 | United States. With a master’s degree in business analysis, specializing in business intelligence and 111 | analytics, he possesses expertise in data-driven decision-making and advanced analytical techniques. 112 | Currently a lead data science analyst at a top Fortune 500 finance company, Raghav leverages data to 113 | drive strategic initiatives, delivering actionable recommendations and optimizing business operations. 114 | Alongside his professional achievements, he is dedicated to empowering aspiring data analysts 115 | through practical writing that bridges the gap between theory and practice. Raghav’s commitment 116 | to innovation, data-driven decision-making, and knowledge sharing continues to shape the future of 117 | data analysis in finance and beyond. 118 | 119 | **Shivangi Saxena,** 120 | a highly accomplished data analyst and Business Intelligence Engineer with over six 121 | years of experience, relocated from India to the United States to pursue a master’s degree in information 122 | technology and management, specializing in business intelligence and analytics. She quickly became 123 | a valuable asset in the industry, leveraging data to drive strategic business decisions with her strong 124 | analytical mindset and passion for technology. Currently working with a top Fortune 500 company, 125 | Shivangi excels in data analysis, visualization, and business intelligence, making her a trusted advisor. 126 | Her ability to derive meaningful insights from complex datasets and translate them into actionable 127 | strategies sets her apart. Committed to empowering others, Shivangi has written this book to help 128 | aspiring data analysts enhance their skills. Her writing combines theory and practical application to 129 | offer valuable guidance. Additionally, Shivangi actively mentors aspiring data professionals, particularly 130 | women, encouraging them to pursue their dreams in the field. Her journey reflects her resilience, 131 | determination, and passion for data analysis, as she continues to inspire others and shape the future 132 | of the industry with her expertise and thought leadership. 133 | 134 | 135 | 136 | --------------------------------------------------------------------------------