Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying SQL Query Design Patterns and Best Practices
  • Table Of Contents Toc
  • Feedback & Rating feedback
SQL Query Design Patterns and Best Practices

SQL Query Design Patterns and Best Practices

By : Steven Hughes, Neer, Ram Babu Singh, Shabbir Mala, Andrews, Zhang
4.7 (10)
close
close
SQL Query Design Patterns and Best Practices

SQL Query Design Patterns and Best Practices

4.7 (10)
By: Steven Hughes, Neer, Ram Babu Singh, Shabbir Mala, Andrews, Zhang

Overview of this book

SQL has been the de facto standard when interacting with databases for decades and shows no signs of going away. Through the years, report developers or data wranglers have had to learn SQL on the fly to meet the business needs, so if you are someone who needs to write queries, SQL Query Design and Pattern Best Practices is for you. This book will guide you through making efficient SQL queries by reducing set sizes for effective results. You’ll learn how to format your results to make them easier to consume at their destination. From there, the book will take you through solving complex business problems using more advanced techniques, such as common table expressions and window functions, and advance to uncovering issues resulting from security in the underlying dataset. Armed with this knowledge, you’ll have a foundation for building queries and be ready to shift focus to using tools, such as query plans and indexes, to optimize those queries. The book will go over the modern data estate, which includes data lakes and JSON data, and wrap up with a brief on how to use Jupyter notebooks in your SQL journey. By the end of this SQL book, you’ll be able to make efficient SQL queries that will improve your report writing and the overall SQL experience.
Table of Contents (21 chapters)
close
close
1
Part 1: Refining Your Queries to Get the Results You Need
6
Part 2: Solving Complex Business and Data Problems in Your Queries
11
Part 3: Optimizing Your Queries to Improve Performance
14
Part 4: Working with Your Data on the Modern Data Platform

Working with the PIVOT operator

A PIVOT operator, simply put, transforms a table output column into rows. It rotates a table-valued expression (a table-valued expression returns output as a result set/table) by turning unique values from a selected column into multiple columns and aggregates the remaining column values in the final table output.

Figure 7.1 – Basic understanding of the PIVOT operator

Figure 7.1 – Basic understanding of the PIVOT operator

The PIVOT operator is very similar to a CASE statement, but much simpler and more easily readable for the user.

Here is the syntax for it:

SELECT
<Unique Column Name(s)>
FROM
<SELECT query to produce data from table(s)>
PIVOT
(
<column to be aggregated, e.g., COUNT, AVG, etc.>
FOR
<Unique Column values that will become column headers>
);

Important

For aggregate functions in the PIVOT operator, any null values in the value column are not considered during computation.

Let’s walk through an example to get a...

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
SQL Query Design Patterns and Best Practices
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon