在Oracle中选择计算列

时间:2018-09-26 00:12:31

标签: sql oracle

SQL新增功能和ORACLE。尝试编写此SELECT语句以创建表视图,但是我没有将其转换为Oracle。谁能帮助我破译它,并通过使它在SQL Developer中正常工作来实现?

SELECT 
OrderItems.orderID, 
Items.itemID, 
Items.itemDescription, 
Items.itemPrice, 
OrderItems.quantity, 
OrderItems.discountPercentage,
(OrderItems.quantity*itemPrice)*(OrderItems.discountPercentage/100) AS discountPerItem, 
(OrderItems.quantity*itemPrice)-((OrderItems.quantity*itemPrice)*(OrderItems.discountPercentage/100)) AS totalOrder 
FROM Inner Join OrderItems on Items.itemID = OrderItems.itemID;

错误,我得到了AS DiscountPerItem:

  

ORA-00923:找不到期望的位置00923,00000-“ FROM的FROM关键字   找不到预期的关键字”   *原因:   *操作:第8行错误:68列

1 个答案:

答案 0 :(得分:1)

您正在使用旧联接,可以尝试

SELECT 
OrderItems.orderID, 
Items.itemID, 
Items.itemDescription, 
Items.itemPrice, 
OrderItems.quantity, 
OrderItems.discountPercentage,
(OrderItems.quantity*Items.itemPrice)*(OrderItems.discountPercentage/100) AS discountPerItem, 
(OrderItems.quantity*Items.itemPrice)-((OrderItems.quantity*Items.itemPrice)*(OrderItems.discountPercentage/100)) AS totalOrder 
FROM Items, OrderItems
Where Items.ItemID = OrderItems.ItemID;

但是我希望您这样做。

SELECT 
OrderItems.orderID, 
Items.itemID, 
Items.itemDescription, 
Items.itemPrice, 
OrderItems.quantity, 
OrderItems.discountPercentage,
(OrderItems.quantity*Items.itemPrice)*(OrderItems.discountPercentage/100) AS discountPerItem, 
(OrderItems.quantity*Items.itemPrice)-((OrderItems.quantity*Items.itemPrice)*(OrderItems.discountPercentage/100)) AS totalOrder 
FROM Items
Inner Join OrderItems on Items.ItemID = OrderItems.ItemsID;