1

这是查询:

select STOCKS.STOCKNO, STOCKS.DESCRIPTION, ORDERITEMS.QTYORD
from STOCKS
left join ORDERITEMS
on STOCKS.STOCKNO = ORDERITEMS.STOCKNO 
WHERE STOCKNO !=(Select STOCKNO from ORDERITEMS where ORDERNO='1' or ORDERNO='2')
ORDER BY STOCKNO
/

这是错误:

ORA-00918: column ambiguously defined for every stock item.. 

我已经完成了连接,但是对于第一个查询但是对于第二个查询是

WHERE STOCKNO !=(Select STOCKNO from ORDERITEMS where ORDERNO='1' or ORDERNO='2')

问题是显示 STOCKS、DESCRIPTION 和 Quantity Ordered,包括到目前为止尚未下订单的库存。

4

3 回答 3

3

哪个股票编号?

WHERE STOCKNO 

要么STOCKS.STOCKNOORDERITEMS.STOCKNO

于 2012-11-30T12:28:31.143 回答
2

尝试使用如下别名并替换!=not in

select S.STOCKNO, S.DESCRIPTION, O.QTYORD
from STOCKS S
left join ORDERITEMS O on S.STOCKNO = O.STOCKNO 
WHERE S.STOCKNO not in (select O2.STOCKNO  
                        from ORDERITEMS O2 
                        where O2.ORDERNO='1' or O2. ORDERNO='2')
ORDER BY S.STOCKNO
/
于 2012-11-30T12:30:28.817 回答
0

确保使用别名。

select 
    s.stockno, 
    s.description, 
    o.qtyord
from stocks s
left join orderitems o
    on s.stockno = o.stockno 
where s.stockno not in ( select stockno from orderitems where orderno in ( '1', '2' ) )
order by s.stockno
;

特别是,您需要使用where s.stockno not in <subquery>.

于 2012-11-30T13:50:21.707 回答