课程: SQL Server Fundamentals: Master Basic Query Techniques
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Solution: Case statement
(upbeat music) - [Instructor] In this solution, I only need to retrieve data that's in the orders table, so I can go ahead and start filtering right away. So we'll say orders as O, and we know we want where the status equals paid, and now we can start writing our subquery, where o.Salesperson.Id is in, we'll write our subquery. Select salesperson ID from salesperson as S. Just for clarity, we'll add that alias to the column there, too, where s.FirstName equals Jane and s.LastName equals Porter. There, our filtering is done, so we'll work on our column list and our case statement, so we need the order ID, the total due. Now, for our case statement, we're going to say case when total due is less than 100, then we'll return one. When total due is between 100 and 150, then we'll return two, and otherwise, so just we'll use else, return three, end our case statement, and give a column alias as order tier, and we're all set. Give it a test, and we're all set!
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。