- 如果订单的 SUM > 100 且 < 200 我需要将价格降低 10%
如果订单的 SUM > 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;
问问题
66 次
1 回答
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
请注意,当 sum=200 时,您的样本中没有折扣。
我建议您需要检查 sum >= 200 。
于 2013-11-01T00:35:38.060 回答