From the course: MySQL Data Analysis

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Pro tip: Pivoting with COUNT and CASE

Pro tip: Pivoting with COUNT and CASE - MySQL Tutorial

From the course: MySQL Data Analysis

Pro tip: Pivoting with COUNT and CASE

- [Narrator] Alright, this next lecture is a pro tip. It's a little more advanced. This is actually something I'll sometimes give as an interview question to try to understand just how far along somebody is with SQL. It's super powerful. I use it probably every day. And what we're talking about here is pivoting your data with Count and Case. The key concept here is that Excel's ability to pivot quickly into columns and rows can be replicated in SQL using Count and Case together. Excel makes it very easy to pivot your data on two dimensions. So here we've got our inventory table, which consists of an inventory ID, a film ID, and a store ID. If we were using Excel, we could very easily pivot that into films down the left and store ID to figure out account of inventory IDs, which are in each store. So what this Excel pivot table is showing us is film 1 has four copies in store one and four copies in store two. Film two has zero copies in store one and three copies in store two. Clearly…

Contents