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

免费学习该课程!

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

Solution: Encourage patrons to check out books

Solution: Encourage patrons to check out books - SQL教程

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

Solution: Encourage patrons to check out books

- [Instructor] This challenge asked us to find information about people who checked out only one book in the year 2024. Here's how I solved this challenge. I need to return information from the database, so I used a SELECT statement. And the values that I'm returning are a count of loans with an alias LoanCount as the challenge requested. And then the patron's first name and email address to make it easy to feed these results into our email system to generate reminder emails. We'll need information from the Loans table. And I'll join this to the Patrons table to get the other two fields. To find loans that were made in 2024, I'm using my WHERE clause here with a BETWEEN statement and the first and last days of the year. This will find any record with a loan date in 2024. Because I'm counting values from the Loans table, I need to group by patron ID so I can get account of loans for each patron. The challenge asked us to look for patrons who borrowed only one book, no more, no less. So…

内容