如果订单的总和> 200,我需要将价格降低20%
BEGIN
FOR item IN(SELECT ORDER_LINE.O_ID,SUM(INVENTORY.INV_PRICE) AS SUM,
SUM(INVENTORY.INV_PRICE) -SUM(INVENTORY.INV_PRICE)*.10 AS TEN,
SUM(INVENTORY.INV_PRICE) -SUM(INVENTORY.INV_PRICE)*.20 AS TWENTY
FROM INVENTORY
INNER JOIN ORDER_LINE
ON INVENTORY.INV_ID = ORDER_LINE.INV_ID
INNER JOIN ITEM
ON ITEM.ITEM_ID = INVENTORY.ITEM_ID
GROUP BY ORDER_LINE.O_ID
ORDER BY ORDER_LINE.O_ID)
IF item.SUM > 100 AND item.SUM < 200 THEN
LOOP
DBMS_OUTPUT.PUT_LINE(
item.O_ID||' '||item.TEN);
END LOOP;
ELSE IF item.SUM > 200 THEN
LOOP
DBMS_OUTPUT.PUT_LINE(
item.O_ID||' '||item.TWENTY);
END LOOP;
END IF;
END;
答案 0 :(得分:0)
您可以在sql中执行此操作:
SELECT
ORDER_LINE.O_ID,
CASE WHEN
SUM(INVENTORY.INV_PRICE) > 100 AND SUM(INVENTORY.INV_PRICE) < 200
THEN
SUM(INVENTORY.INV_PRICE)*0.9
WHEN SUM(INVENTORY.INV_PRICE) > 200 THEN
SUM(INVENTORY.INV_PRICE)*0.8
ELSE
SUM(INVENTORY.INV_PRICE)
END SUM
FROM INVENTORY
INNER JOIN ORDER_LINE
ON INVENTORY.INV_ID = ORDER_LINE.INV_ID
INNER JOIN ITEM
ON ITEM.ITEM_ID = INVENTORY.ITEM_ID
GROUP BY ORDER_LINE.O_ID
ORDER BY ORDER_LINE.O_ID
当总和= 200时,请注意样品中没有折扣 我建议你需要检查总和&gt; = 200。