使用oracle来编写sql语句,给了一些功课我还没有彻底理解/努力去掌握(所以如果你有任何好的教程/链接基本的sql程序/函数,将不胜感激。
存储过程,列出了La Trobe电子拍卖数据库系统中所有项目的名称,描述和值,以及显示以下内容的列: 如果拍卖已经结束且商品已售出,则“已售出” 如果拍卖已经结束并且没有为该项目进行投标,则“不出价” 如果拍卖已经结束但未达到底价,则“不出售”
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)
这是我已经解决的理论,但我对如何编码它感到茫然。
status column - a)sold, closed and item is sold
b)no bid, auction is close and no bids
c)no sale, the auction is closed but reserve wasnt met
d)on auction, auction for the item is still open
a) if i.itemnumber=a.itemnumber and itemSold='y'
b) if a.auctionnumber != b.auctionnumber and systemdate>endDateTime
c) if sysdate>endDatetime and a.auctionnumber=b.auctionnumber
and reserveamount>select b.bidAmount
from bid where a.auctionnumber=b.auctionnumber
and b.bidAmount.max;
d) if itemSold ='n' and sysdate<endDateTime;
CREATE OR REPLACE PROCEDURE allItemStatus
AS
p_itemName Item.itemName%TYPE;
p_itemDescription Item.itemDescription%TYPE;
p_itemValue Item.itemValue%TYPE;
P_itemSold Auction.itemSold%TYPE;
BEGIN
SELECT i.itemName, i.itemDescription, i.itemValue, a.itemSold
INTO p_itemName, p_itemDescription, p_itemValue , p_itemSold
FROM dbf12.Item i, dbf12.Auction a
WHERE i.itemNumber=a.itemNumber
AND a.itemSold='Y';
DBMS_OUTPUT.PUT_LINE('Item Name: '||p_itemName);
DBMS_OUTPUT.PUT_LINE('Item Description: '||p_itemDescription);
DBMS_OUTPUT.PUT_LINE('Item Value: '||p_itemValue);
DBMS_OUTPUT.PUT_LINE('Item Sold: '||p_itemSold);
END allItemStatus;
任何帮助将不胜感激。我知道我几乎没有写出整件事,但我不知道该怎么做。
这是我当前的代码,它不喜欢我的sysdate&gt; a.enddattime
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 systemdate>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
WHERE a.auctionnumber=b.auctionnumber
AND b.bidAmount.max) THEN 'No Bids that meets the reserve'
ELSE 'Auction Still Open'
END
FROM
dbf12.item i, dbf12.auction a, dbf12.bid b;
答案 0 :(得分:1)
使用CASE语句
SELECT
itemname,
itemdescription,
itemvalue,
CASE
WHEN status=1 THEN 'Sold'
WHEN status=2 THEN 'No Bid'
WHEN status=3 AND (another condition here) THEN 'Closed'
ELSE 'What Else'
END display
FROM
eAuction
“display”是显示“已售出”等的列的名称。