2012-05-30 130 views
0

大家好,我得到一個SQL查詢,我只是不知道類,並想知道我可以得到一些幫助。這裏的問題是: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

上'GROUP BY' – Paddy

+0

你在使用閱讀嗎? mssql,mysql,oracle – Arion

+0

mysql/oracle Arion – KageArarshi

回答

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);