【问题标题】:ORA-00907 error at order by in Oracle 11gOracle 11g 中的 ORA-00907 错误
【发布时间】:2020-11-21 14:58:45
【问题描述】:
select Customer_Name from Customer where Customer_Id IN 
(select distinct Customer.Customer_Id from Customer join Toy_Rental on Toy_Rental.Customer_ID=Customer.Customer_Id 
order by Toy_Rental.Total_Amount desc 
fetch next 2 rows only);

【问题讨论】:

标签: oracle oracle11g


【解决方案1】:

11g 中没有FETCH 子句;它在 12c 中可用。

看看这是否有帮助:

select a.Customer_Name 
from Customer a
where a.Customer_Id IN (select x.customer_id
                        from (select c.Customer_Id 
                              from Customer c join Toy_Rental t on t.customer_id = c.customer_id
                              order by t.total_amount desc
                             ) x
                        where rownum <= 2
                       )

或者:

with cust as
  (select c.customer_id
          row_number() over (order by t.total_amount desc) rn
   from customer c join toy_rental t on t.customer_id = c.customer_id
  )
select a.customer_name
from customer a join cust x on x.customer_id = a.customer_id
where x.rn <= 2

【讨论】:

    猜你喜欢
    • 2018-05-27
    • 2013-07-18
    • 1970-01-01
    • 1970-01-01
    • 2018-07-18
    • 1970-01-01
    • 2016-11-22
    • 2013-08-24
    • 1970-01-01
    相关资源
    最近更新 更多