大家都有一个我无法在课堂上找到的SQL查询,并且想知道我能得到一些帮助。这是一个问题:
显示“获胜会员列表”:已赢得出价的会员列表以及该项目的项目名称,项目值和中标金额。我的代码只显示所有代码中的最高出价而不是每个成员的最高出价
表格:
Member (username, lastName, firstName, title, address, city, postcode, country,
phoneBH, phoneAH, faxNumber, email, registrationDate, password, isBuyer,
isSeller)
Item (itemNumber, itemName, itemDescription, itemValue, itemLocation,
categoryID, sellerUsername)
Auction (auctionNumber, currency, startDateTime, endDateTime, shippingTerms,
startBidAmount, reserveAmount, bidIncrementAmount, noOfItems, itemSold,
itemNumber feedbackDateAndTime, rating, comments, paymentDate, paymentid)
Bid (bidderUsername, auctionNumber, bidDateTime,bidAmount)
SELECT B.bidderUsername, I.itemName, I.itemValue, B.bidAmount, A.auctionNumber
FROM Item I, Auction A, Bid B
WHERE A.auctionNumber = B.auctionNumber
AND I.itemNumber = A.itemNumber
AND B.bidAmount >= A.reserveAmount
AND A.endDateTime < SYSDATE
AND B.bidAmount = (SELECT max(B.bidAmount)
FROM dbf12.Bid B, dbf12.Auction A
WHERE B.auctionNumber = A.auctionNumber)
对于代码和表格,您可能需要选择代码/表格并按ctrl-k
答案 0 :(得分:1)
我修好了。我指的是我的子查询中的错误表。 这是正确的代码
SELECT B.bidderUsername, I.itemName, I.itemValue, B.bidAmount, A.auctionNumber
FROM dbf12.Item I, dbf12.Auction A, dbf12.Bid B
WHERE A.auctionNumber = B.auctionNumber
AND I.itemNumber = A.itemNumber
AND B.bidAmount >= A.reserveAmount
AND A.endDateTime < SYSDATE
AND B.bidAmount = (SELECT max(B.bidAmount)
FROM dbf12.Bid B
WHERE B.auctionNumber = A.auctionNumber);