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.

COUNT and CASE demo

COUNT and CASE demo - MySQL Tutorial

From the course: MySQL Data Analysis

COUNT and CASE demo

- [Instructor] All right, now we're going to go through a real example using CASE and COUNT to create the CASE pivoting method. Excel makes it very easy to pivot your data into columns and rows using a pivot table. We're going to be able to recreate that functionality in MySQL by using GROUP BY and combining it with the CASE pivot method. When we're CASE pivoting, we're using COUNT and we're only counting records that match a certain criteria. My pro tip for this is to use GROUP BY to define your rows and think of the CASE pivot as how you pivot to columns. Here's an example of the CASE pivot in action. We're going to jump into Workbench and walk through it step by step. Okay, here we've got a SELECT * on our inventory table. What you see here is inventory_id, which represents one item of inventory, which is a film that is held at a particular store. So in this CASE, inventory_id 1 is film number one at store number 1. inventory_id 7 is film number 1, but it's at store number 2. So in…

Contents