select county_id from t_area_county
where county_id not in
(select county_id from t_area_county where rownum <= 30 order by county_id desc)
and rownum <= 15 order by county_id desc
在ORACLE提示“缺少右括号”,应该就是嵌套查询的order by county_id desc不能这样使用,请问该如何使用呢
where county_id not in
(select county_id from t_area_county where rownum <= 30 order by county_id desc)
and rownum <= 15 order by county_id desc
在ORACLE提示“缺少右括号”,应该就是嵌套查询的order by county_id desc不能这样使用,请问该如何使用呢
select county_id
from t_area_county
where county_id not in (select county_id
from (select county_id, rownum rn
from t_area_county
order by county_id desc)
where rn <= 30)
and rownum <= 15
order by county_id desc
2 aa where id not in (select id from dd where rownum<=10 order by id desc)
3 and rownu<=16 order by id desc;
aa where id not in (select id from dd where rownum<=10 order by id desc)
*
ERROR at line 2:
ORA-00907: missing right parenthesis
SQL> create or replace view v_sql as select id from dd where rownum<=10 order by id desc; View created.SQL> select * from aa where id not in (select * from v_sql)
2 and rownum<=16 order by id desc; ID NAME
---------- --------------------
26 ll
25 ll
24 ll
23 ll
22 ll
21 ll
20 ll
19 ll
18 ll
17 ll
16 ll ID NAME
---------- --------------------
15 ll
14 ll
13 ll
12 ll
11 ll16 rows selected.
但是我有一点提醒你,你写这个语句的需求是干什么?我觉得你的语句的逻辑可能有些问题.特别是这一句:select county_id from t_area_county where rownum <= 30 order by county_id desc
如果你是想按排序,然后取得前30的话,那么这个语句是错误的.