为什么我会收到错误:使用的列部分不能有限定符

时间:2014-12-09 17:39:30

标签: sql oracle join using ambiguous

这是我正在尝试运行的查询:

select
   ordervariety,
   bat.batch,
   order_date,
   var.variety,
   var.the_name,
   bat.the_name,
   var.the_price,
   bat.the_price
   quantity
from
   test_orders
   join TEST_ORDERVARIETIES using (orderno)
   full outer join assessment_varieties var using (variety)
   full outer join test_batches bat using (batch)
where
   ordervariety is not null

表格结构如下: TEST_ORDERS:

Column Name Data Type   Nullable    Default Primary Key
ORDERNO NUMBER(6,0) No  -   1
SHOP    NUMBER(3,0) No  -   -
ORDER_DATE  DATE    No  -   -

TEST_ORDERVARIETIES:

ORDERVARIETY    NUMBER(6,0) No  -   1
ORDERNO NUMBER(6,0) No  -   -
VARIETY NUMBER(6,0) Yes -   -
BATCH   NUMBER(6,0) Yes -   -
QUANTITY    NUMBER(3,0) No  -   -

TEST_BATCHES:

Column Name Data Type   Nullable    Default Primary Key
BATCH   NUMBER(6,0) No  -   1
GREENHOUSE  NUMBER(3,0) No  -   -
THE_NAME    VARCHAR2(50)    No  -   -
VARIETY NUMBER(3,0) No  -   -
THE_PRICE   NUMBER(5,2) Yes -   -

ASSESSMENT_VARIETIES:

Column Name Data Type   Nullable    Default Primary Key
VARIETY NUMBER(6,0) No  -   1
SPECIES NUMBER(6,0) No  -   -
THE_NAME    CHAR(64)    Yes -   -
THE_PRICE   NUMBER(8,2) Yes -   -
THE_GROWING_NOTES   CHAR(255)   Yes -   -

为什么我会收到错误:ORA-25154:USING子句的列部分不能有限定符?

我该怎么做才能解决这个问题?谢谢!

2 个答案:

答案 0 :(得分:2)

将您的select更改为:

select
   ordervariety,
   bat.batch,
   order_date,
   variety,
---^
   var.the_name,
   bat.the_name,
   var.the_price,
   bat.the_price
   quantity

使用USING时,不能在子句中使用的列中包含表别名。

编辑:

问题是variety三个表中,但仅在using子句中用于其中两个表之间的连接。我建议只是明确关于连接:

select ov.ordervariety, bat.batch, o.order_date,
       var.variety, var.the_name,
       bat.the_name, var.the_price, bat.the_price
       ov.quantity
from test_orders o join
     TEST_ORDERVARIETIES ov
     on o.orderno = ov.oderno full outer join 
     assessment_varieties var
     on var.variety = ov.variety join
     test_batches bat
     on b.batch = ov.batch
where ov.ordervariety is not null;

答案 1 :(得分:0)

从批处理中删除bat,从SELECT语句中删除var。

您无法在SELECT区域中对这些字词使用别名,因为您已在JOIN区域对其进行了限定。

 SELECT batch, variety, bat.the_price