0

私のSQLクエリは、20を吐き出すはずのときに、3000のクエリを吐き出します。私は、Oracleを使用しています。

表は次のとおりです。

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
   i.itemname,
   i.itemdescription,
   i.itemvalue,
   CASE
       WHEN i.itemnumber=a.itemnumber and a.itemSold='y' THEN 'Sold'
       WHEN a.auctionnumber != b.auctionnumber and TO_CHAR(sysdate,'DD-MON-YY')>endDateTime THEN 'No Bids on that closed auction'
       WHEN TO_CHAR(sysdate,'DD-MON-YY')<a.endDatetime and a.auctionnumber=b.auctionnumber 
                 and reserveamount>(
                 SELECT b.bidAmount
                 FROM dbf12.bid b, dbf12.auction a               
                 WHERE a.auctionnumber=b.auctionnumber 
                 GROUP BY b.bidAmount
                 HAVING b.bidAmount= max(b.bidAmount)) THEN 'No Bids that meets the reserve'
        ELSE 'Auction Still Open'
   END 
FROM 
   dbf12.item i, dbf12.auction a, dbf12.bid b;
4

1 に答える 1

2

dbf12.item、dbf12.auction、およびdbf12.bidの間の結合基準を忘れたようです。これにより、基本的に3つのテーブルの外積になり、各テーブルのすべての行が他のすべての行のすべての行に結合されます。

次のようなものを試してください。

SELECT
   i.itemname,
   i.itemdescription,
   i.itemvalue,
   CASE
       WHEN i.itemnumber=a.itemnumber and a.itemSold='y' THEN 'Sold'
       WHEN a.auctionnumber != b.auctionnumber and TO_CHAR(sysdate,'DD-MON-YY')>endDateTime THEN 'No Bids on that closed auction'
       WHEN TO_CHAR(sysdate,'DD-MON-YY')<a.endDatetime and a.auctionnumber=b.auctionnumber 
                 and reserveamount>(
                 SELECT b.bidAmount
                 FROM dbf12.bid b, dbf12.auction a               
                 WHERE a.auctionnumber=b.auctionnumber 
                 GROUP BY b.bidAmount
                 HAVING b.bidAmount= max(b.bidAmount)) THEN 'No Bids that meets the reserve'
        ELSE 'Auction Still Open'
   END 
FROM 
   dbf12.item i, dbf12.auction a, dbf12.bid b
    WHERE i.itemnumber = a.itemnumber and b.actionnumber = a.auctionnumber

次のように言うこともできます。

SELECT
   i.itemname,
   i.itemdescription,
   i.itemvalue,
   CASE
       WHEN i.itemnumber=a.itemnumber and a.itemSold='y' THEN 'Sold'
       WHEN a.auctionnumber != b.auctionnumber and TO_CHAR(sysdate,'DD-MON-YY')>endDateTime THEN 'No Bids on that closed auction'
       WHEN TO_CHAR(sysdate,'DD-MON-YY')<a.endDatetime and a.auctionnumber=b.auctionnumber 
                 and reserveamount>(
                 SELECT b.bidAmount
                 FROM dbf12.bid b, dbf12.auction a               
                 WHERE a.auctionnumber=b.auctionnumber 
                 GROUP BY b.bidAmount
                 HAVING b.bidAmount= max(b.bidAmount)) THEN 'No Bids that meets the reserve'
        ELSE 'Auction Still Open'
   END 
    from db12.item i
        inner join dbf12.auction a on a.itemnumber = i.itemnumber
        inner join dbf12.bid b on b.auctionnumber = a.auctionnumber
于 2012-05-31T06:17:27.810 に答える