好的,我已经仔细阅读了这个网站,这里有一些成员建议,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。
答案 0 :(得分: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行正在加入错误的表格
答案 1 :(得分:0)
Yeap,再次加入:)
INNER JOIN CUSTOMER INNER JOIN ORDERS ON
您错过了ON
中的CUSTOMER
,或者您有额外的INNER JOIN CUSTOMER
。很可能是第二个。
答案 2 :(得分: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()”,您可以将列直接乘以每行总金额,因为您显示的是实际订购的每个零件。
还要注意每个表的简化别名引用和重复写入每个表名的全长。