关于连接或子查询的sql oracle问题

问题描述 投票:1回答:1
select *
from amazon_shipment, customer
where amazon_shipment.customer_id = customer.customer_id 
and amazon_shipment.customer_id in 
    (select top(1) amazon_shipment.customer_id
    from amazon_shipment 
    group by amazon_shipment.customer_id
    order by count(*) desc);

我试图选择订单最多的所有客户,但是,我收到一个错误:

找不到FROM关键字

oracle-sqldeveloper
1个回答
0
投票

TOP(1)在Oracle中不可用。

在Oracle 11gR2及更低版本中,您可以使用WHERE ROWNUM <2

select *
  from EMPLOYEES
 where rownum < 2
 order by SALARY desc;

在Oracle 12c及更高版本中,您只能使用FETCH FIRST 1 ROWS

select *
  from EMPLOYEES
 order by SALARY desc
 fetch first 1 rows only;
© www.soinside.com 2019 - 2024. All rights reserved.