To a large extent business users want to visualize data in a tabular format as shown below. This is a good presentation however, it takes 3 rows just to present data for CustomerID 11000 and 31406 rows to present data for all the CustomerIDs.
What if your requirement is to represent each year as an individual column so that in a single row, you can view the Total per CustomerID for each OrderYear? Pivot is a T-SQL operator that can be use used to achieve this. Pivot basically flips rows into columns. Let’s look at the the example below. In this case, all the data for CustomerID 11000 is presented on a single row. It takes 19119 rows to present all the data for all the CustomerIDs.
In a nutshell, Pivot allows to summarize data by rotating rows into columns.
Thanks for reading and keep loving SQL 🙂
This was very informative. Helped me breakdown pivots 😀
LikeLike