课程: SQL Hands-On Practice: Solve Business Problems
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
Solution: Creating binary columns with CASE - SQL教程
课程: SQL Hands-On Practice: Solve Business Problems
Solution: Creating binary columns with CASE
- [Instructor] Now that you've had the chance to practice case on your own, let's solve this problem together. Sometimes in business, we want to identify or mark observations that meet a certain condition by using a binary column that consists of ones and zeros. This is also called a flag. You can think of it as a light switch. When the condition is true, the value in the binary column is one. And when the condition is false, the value is zero. Technically, you could assign the ones and zeros any way you want. But typically it's a best practice and widely accepted to flag the on condition with one and the off condition with zero. Since this column requires us to flag upsell opportunities that meet two conditions, this tells us that we need case, so we can categorize companies into ones and zeros row by row. First, let's write the starting point for the query. We need to first aggregate the number of products and…