帮助SQL查询

nub*_*ela 0 sql

这是DB Schema:

Books (bookid, title, author, year)
Customers (customerid, name, email)
Purchases (customerid, bookid, year)
Reviews (customerid, bookid, rating)
Pricing (bookid, format, price)
Run Code Online (Sandbox Code Playgroud)

如何找到在2003年购买多本书的客户(显示他们的姓名和电子邮件地址)?

谢谢!

sou*_*rge 5

SELECT name, email, COUNT(p.customerId) as purchases_in_2003
FROM Customers c
INNER JOIN Purchases p ON c.customerId = p.customerId
WHERE p.year = 2003
GROUP BY name, email
HAVING purchases_in_2003 > 1
Run Code Online (Sandbox Code Playgroud)