我的尝试如下:

SELECT BookLoan.borrowerName, Book.cost
FROM BookLoan
JOIN Book ON BookLoan.bookTitle = Book.title
JOIN Borrower ON BookLoan.borrowerName = Borrower.name;


我需要按borrowerName组合总费用,但真的不确定如何?

最佳答案

SELECT BookLoan.borrowerName, SUM(Book.cost) as TotalCost
FROM BookLoan
JOIN Book ON BookLoan.bookTitle = Book.title
JOIN Borrower ON BookLoan.borrowerName = Borrower.name
GROUP BY BookLoan.borrowerName

09-17 18:56