0

嗨,我正在使用 orcale,并且我在表之间创建了一个连接。我现在正在尝试插入一个计算,但它不断出现相同的错误消息“ORA-00933:SQL 命令未正确结束”我生成的代码是这个..

select   "CUSTOMER"."CUST_ID" as "CUST_ID",
 "CUSTOMER"."CUST_TITLE" as "CUST_TITLE",
 "CUSTOMER"."CUST_FORENAME" as "CUST_FORENAME",
 "CUSTOMER"."CUST_SURNAME" as "CUST_SURNAME",
 "CUSTOMER"."CUST_ADDRESS_1" as "CUST_ADDRESS_1",
 "CUSTOMER"."CUST_ADDRESS_2" as "CUST_ADDRESS_2",
 "CUSTOMER"."CUST_TOWN-CITY" as "CUST_TOWN-CITY",
 "CUSTOMER"."CUST_COUNTY" as "CUST_COUNTY",
 "CUSTOMER"."CUST_POST_CODE" as "CUST_POST_CODE",
 "CUSTOMER"."CUST_TEL" as "CUST_TEL",
 "CUSTOMER"."CUST_EMAIL" as "CUST_EMAIL",
 "MENU_ITEM"."PRODUCT_PRICE" as "PRODUCT_PRICE",
 "ORDER_ITEM"."QUANTITY" as "QUANTITY",
 "ORDER_ITEM"."ORDER_ID" as "ORDER_ID",
 "ORDER_DETAILS"."ORDER_ID" as "ORDER_ID"
from     "ORDER_DETAILS" "ORDER_DETAILS",
 "ORDER_ITEM" "ORDER_ITEM",
 "MENU_ITEM" "MENU_ITEM",
 "CUSTOMER" "CUSTOMER"
where   "ORDER_ITEM"."ORDER_ID"="ORDER_DETAILS"."ORDER_ID"
 and     "ORDER_DETAILS"."CUST_ID"="CUSTOMER"."CUST_ID"
 and     "MENU_ITEM"."MENU_ITEM_ID"="ORDER_ITEM"."MENU_ITEM_ID"`

这是产生错误信息的代码

 select  "CUSTOMER"."CUST_ID" as "CUST_ID",
 "CUSTOMER"."CUST_TITLE" as "CUST_TITLE",
 "CUSTOMER"."CUST_FORENAME" as "CUST_FORENAME",
 "CUSTOMER"."CUST_SURNAME" as "CUST_SURNAME",
 "CUSTOMER"."CUST_ADDRESS_1" as "CUST_ADDRESS_1",
 "CUSTOMER"."CUST_ADDRESS_2" as "CUST_ADDRESS_2",
 "CUSTOMER"."CUST_TOWN-CITY" as "CUST_TOWN-CITY",
 "CUSTOMER"."CUST_COUNTY" as "CUST_COUNTY",
 "CUSTOMER"."CUST_POST_CODE" as "CUST_POST_CODE",
 "CUSTOMER"."CUST_TEL" as "CUST_TEL",
 "CUSTOMER"."CUST_EMAIL" as "CUST_EMAIL",
 "MENU_ITEM"."PRODUCT_PRICE" as "PRODUCT_PRICE",
 "ORDER_ITEM"."QUANTITY" as "QUANTITY",
 "ORDER_ITEM"."ORDER_ID" as "ORDER_ID",
 "ORDER_DETAILS"."ORDER_ID" as "ORDER_ID"
   from  "ORDER_DETAILS" "ORDER_DETAILS",
 "ORDER_ITEM" "ORDER_ITEM",
 "MENU_ITEM" "MENU_ITEM",
 "CUSTOMER" "CUSTOMER"
where   "ORDER_ITEM"."ORDER_ID"="ORDER_DETAILS"."ORDER_ID"
 and     "ORDER_DETAILS"."CUST_ID"="CUSTOMER"."CUST_ID"
 and     "MENU_ITEM"."MENU_ITEM_ID"="ORDER_ITEM"."MENU_ITEM_ID"
SELECT PRODUCT_PRICE,
       QUANTITY, 
       PRODUCT_PRICE * QUANTITY AS "TOTAL SPENT"
FROM   MENU_ITEM,ORDER_ITEM
4

1 回答 1

2

SQL 的问题是您的第二个“SELECT”语句打开了一个新的 SQL 命令。如果您想在查询中添加一个名为“TOTAL_SPENT”的新列,该列将 PRODUCT_PRICE 和 QUANTITY 相乘,请将其添加到主查询的 SELECT 列表中。添加第二个 SELECT 语句不会将结果合并到第一个中。

你想要这样的东西:

select  "CUSTOMER"."CUST_ID" as "CUST_ID",
 "CUSTOMER"."CUST_TITLE" as "CUST_TITLE",
 "CUSTOMER"."CUST_FORENAME" as "CUST_FORENAME",
 "CUSTOMER"."CUST_SURNAME" as "CUST_SURNAME",
 "CUSTOMER"."CUST_ADDRESS_1" as "CUST_ADDRESS_1",
 "CUSTOMER"."CUST_ADDRESS_2" as "CUST_ADDRESS_2",
 "CUSTOMER"."CUST_TOWN-CITY" as "CUST_TOWN-CITY",
 "CUSTOMER"."CUST_COUNTY" as "CUST_COUNTY",
 "CUSTOMER"."CUST_POST_CODE" as "CUST_POST_CODE",
 "CUSTOMER"."CUST_TEL" as "CUST_TEL",
 "CUSTOMER"."CUST_EMAIL" as "CUST_EMAIL",
 "MENU_ITEM"."PRODUCT_PRICE" as "PRODUCT_PRICE",
 "ORDER_ITEM"."QUANTITY" as "QUANTITY",
 "ORDER_ITEM"."ORDER_ID" as "ORDER_ID",
 "ORDER_DETAILS"."ORDER_ID" as "ORDER_ID",
 PRODUCT_PRICE * QUANTITY AS "TOTAL SPENT"
   from  "ORDER_DETAILS" "ORDER_DETAILS",
 "ORDER_ITEM" "ORDER_ITEM",
 "MENU_ITEM" "MENU_ITEM",
 "CUSTOMER" "CUSTOMER"
where   "ORDER_ITEM"."ORDER_ID"="ORDER_DETAILS"."ORDER_ID"
 and     "ORDER_DETAILS"."CUST_ID"="CUSTOMER"."CUST_ID"
 and     "MENU_ITEM"."MENU_ITEM_ID"="ORDER_ITEM"."MENU_ITEM_ID"

根据其他表中的列,您可能需要使用它们的表名来限定 PRODUCT_PRICE 和 QUANTITY,就像 SQL 中的其他列引用一样。

于 2013-03-18T21:57:46.627 回答