From the course: Introduction to SQL Using Google BigQuery
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
PIVOT function - SQL Tutorial
From the course: Introduction to SQL Using Google BigQuery
PIVOT function
- [Instructor] Pivoting data from long data sets which have multiple rows to wide data sets with multiple columns is a very common task in data analysis projects. Wide data sets can often be easier to interpret or understand. However, they can also be a pain to build from scratch, especially in SQL as the code can get pretty verbose and complex. BigQuery is really excellent for pivoting data as there is a unique pivot operator, which helps us make this exact transformation. The benefits of having access to the BigQuery pivot operator means that we can keep our code much simpler as opposed to writing out long SQL statements using other means such as a max case when statement. However, we'll learn how to implement both methods together as the pivot operator does have some limitations in BigQuery and it's also a function which is not available in other SQL dialects. Firstly, let's prepare a data set which we can use for this…