-1

好的,我已经阅读了这个网站,这里的成员建议的一对夫妇,sql 教科书等。问题:列出客户姓名、订单日期、订购数量、报价、账单金额和从 Premiere Products 订购的商品的描述。按订单日期和客户名称组织此报告表格:

SQL> desc customer
 Name
 ----------------------
 CUSTOMER_NUM
 CUSTOMER_NAME
 STREET
 CITY
 STATE
 ZIP
 BALANCE
 CREDIT_LIMIT
 REP_NUM

SQL> desc orders
 Name
 ----------------------
 ORDER_NUM
 ORDER_DATE
 CUSTOMER_NUM

SQL> desc order_line
 Name
 ----------------------
 ORDER_NUM
 PART_NUM
 NUM_ORDERED
 QUOTED_PRICE

SQL> desc part
 Name
 ----------------------
 PART_NUM
 DESCRIPT
 ON_HAND
 CLASS
 WAREHOUSE
 PRICE

这是我用于查询的内容:

SQL>  SELECT CUSTOMER.CUSTOMER_NAME, ORDERS.ORDER_DATE,
  2   ORDER_LINE.NUM_ORDERED, ORDER_LINE.QUOTED_PRICE,
  3   SUM(Num_Ordered*Quoted_Price) AS Amt_Billed,
  4   PART.DESCRIPT
  5   FROM customer
  6   INNER JOIN CUSTOMER INNER JOIN ORDERS ON
             CUSTOMER.CUSTOMER_NUM =ORDERS.CUSTOMER_NUM
  7   INNER JOIN ORDER_LINE ON ORDERS.ORDER_NUM = ORDER_LINE.ORDER_NUM
  8   Inner JOIN ORDER_LINE ON PART.PART_NUM = ORDER_LINE.PART_NUM;
 Inner JOIN ORDER_LINE ON PART.PART_NUM = ORDER_LINE.PART_NUM
                                                            *
ERROR at line 8:
ORA-00905: missing keyword

试了好几次,还做了个访问表,里面的SQL和我这里的基本一样。我正在使用 Oracle 11g。

4

3 回答 3

0

格式化 SQL 有助于跟踪表之间的关系。请注意我的简化缩进并显示连接到右侧的左侧表,并且 ON 子句显示它们之间的列关系。

完成后,获取其余列以进行选择、求和、分组、排序等

SELECT
      c.customer_name,
      o.order_date,
      ol.num_ordered,
      ol.quoted_price,
      ol.num_ordered * ol.quoted_price as amt_Billed,
      p.descript
   from
      customer c
         join orders o
            ON c.customer_num = o.customer_num
            join order_line ol
               ON o.order_num = ol.order_num
               join part p
                  ON ol.part_num = p.part_num
   order by
      o.order_date,
      c.customer_name

由于您的查询显示订购的每行项目的数量,因此您不需要“SUM()”,您可以将列直接乘以每行总金额,因为您显示实际订购的每个部分。

还要注意每个表的简化别名引用与重复写入每个表名的全长。

于 2013-10-04T02:22:32.173 回答
0

尝试

    SQL>  SELECT CUSTOMER.CUSTOMER_NAME, ORDERS.ORDER_DATE,
   ORDER_LINE.NUM_ORDERED, ORDER_LINE.QUOTED_PRICE,
   SUM(Num_Ordered*Quoted_Price) AS Amt_Billed,
   PART.DESCRIPT
   FROM customer
   INNER JOIN ORDERS ON CUSTOMER.CUSTOMER_NUM =ORDERS.CUSTOMER_NUM
   INNER JOIN ORDER_LINE ON ORDERS.ORDER_NUM = ORDER_LINE.ORDER_NUM
   Inner JOIN PART ON PART.PART_NUM = ORDER_LINE.PART_NUM;

第 6 行是一个错误的JOIN陈述

第 8 行加入了错误的表

于 2013-10-04T00:49:22.767 回答
0

是的,再次加入:)

INNER JOIN CUSTOMER INNER JOIN ORDERS ON

你错过了ONinCUSTOMER或者你有一个额外的INNER JOIN CUSTOMER. 很可能是第二个。

于 2013-10-04T00:49:43.857 回答