Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 在oracle 11的子查询中使用rownum_Sql_Oracle_Oracle11g - Fatal编程技术网

Sql 在oracle 11的子查询中使用rownum

Sql 在oracle 11的子查询中使用rownum,sql,oracle,oracle11g,Sql,Oracle,Oracle11g,我有这样的查询。它在oracle 12上正常工作 select * from customers where customerId IN (select custId from Orders where orderStatus = 'S' and orderCity = 'Amsterdam' and ORDER BY custId DESC FETCH FIRST 10 ROWS ONLY) 但我使用的是oracle 11。该查询在oracle 11上不起作用。因此,我这样更改了我的

我有这样的查询。它在oracle 12上正常工作

select * from customers where customerId IN (select custId from Orders where 
   orderStatus = 'S' and orderCity = 'Amsterdam' and ORDER BY custId DESC FETCH FIRST 10 ROWS ONLY)
但我使用的是oracle 11。该查询在oracle 11上不起作用。因此,我这样更改了我的查询

select * from customers where customerId IN (select custId from Orders where 
  orderStatus = 'S' and orderCity = 'Amsterdam' and ORDER BY custId DESC rownum <= 10)
它给了缺失的权利


如何解决这个问题。你知道吗?实际上我在10号上使用了一个变量。

语法有点不同-你需要一个额外的子查询,所以它需要更像。。。 其中,select*from中的customerId从orderStatus='S'和orderCity='Amsterdam'的订单中选择custId,以及ORDER BY custId DESC,其中rownum我将使用exists和row_编号来表达:


行号按子查询中客户id的降序排列订单。然后,我们筛选前10行,并使用exists筛选外部查询中的对应行。

我认为代码在语法上是正确的,尽管我建议使用order by。请发布实际查询,因为您缺少and-WHERE。。。rownum我更新了我的问题语法,这有点不同-您需要一个额外的子查询,这样它就需要更像是select*from select custId from Orders中的where customerId,其中orderStatus='S'和ORDERSCITY='Amsterdam',ORDER BY custId DESC中的where rownum
select c.* 
from customers 
where exists (
    select 1
    from (
        select custId, row_number() over(order by custid desc) rn
        from orders 
        where orderStatus = 'S' and orderCity = 'Amsterdam'
    ) o
    where o.rn <= 10 and o.cusid = c.customerid
)