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の問題は、2番目の「SELECT」ステートメントが新しいSQLコマンドを開くことです。PRODUCT_PRICEとQUANTITYを乗算する「TOTAL_SPENT」という新しい列をクエリに追加する場合は、メインクエリのSELECTリストに追加します。2番目の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"

他のテーブルの列によっては、SQLの他の列参照と同様に、PRODUCT_PRICEとQUANTITYをテーブル名で修飾する必要がある場合があります。

于 2013-03-18T21:57:46.627 に答える