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 - 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
The CASE statement2m 43s
-
CASE example5m 43s
-
(Locked)
Common CASE operators4m 18s
-
(Locked)
Challenge: The CASE statement39s
-
(Locked)
Solution: The CASE statement3m 47s
-
(Locked)
Pro tip: Pivoting with COUNT and CASE2m 54s
-
(Locked)
COUNT and CASE demo7m 29s
-
(Locked)
Challenge: COUNT and CASE48s
-
(Locked)
Solution: COUNT and CASE3m 15s
-
(Locked)
-
-
-