课程: Hands-On SQL Challenges: Test Your Knowledge

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Solution: Find books to feature for an event

Solution: Find books to feature for an event - SQL教程

课程: Hands-On SQL Challenges: Test Your Knowledge

Solution: Find books to feature for an event

- [Instructor] This challenge has a few components, and here's how I solved it. We were asked to find the quantity or count of books which were published in a specific range of years, so I'm using the COUNT of the Title with an alias of Qty for quantity, like the challenge asked, and then the Title field itself. These values come from the Books table. To find the books that were published in the 1890s, I used the BETWEEN operator to set an inclusive range of values as my WHERE condition. In our database, the published value is an integer. Next, I need to ensure that the books within that range are actually available in the library and that they're not checked out to a patron. So I'm using the AND operator here with WHERE to add another condition. That condition is that the BookID is not found in the list of books with NULL return dates. This subquery returns a list of books that aren't available in the library, and then the WHERE clause checks whether the expression BookID NOT IN that…

内容