请教你,一个查询难题!请指导小弟!!! 
这有两张表
table A , table B我想查找:
表A中前20条是
(条件一)最大的 a.id 的记录且
(条件二)表A中的id 不在表B的查询条件(select B.id from B where B.content is not null) 减去A中前10条是
(条件一)最大的 a.id 的记录且
(条件二)表A中的id 不在表B的查询条件(select B.id from B where B.content is not null) 可我的查询语句:
select * from A a
where a.id in
(select b.id
from A b
where rownum <= 20 and b.id in
(select id from B where content is not null) 
) and
a.id not in
(select f.id
from A f
where rownum <= 10 and f.id in 
(select id from B where content is not null) 
)order by id desc只能查找我只能查到:
(条件二)表A中的id 在表B的id 中:查询条件 表A中的id in (select id from B where content is not null) 可我想请教各位大侠:
也能实现:
(条件一)表A中前20条最大的 a.id 的记录
减去
(条件一)表A中前10条最大的 a.id 的记录

解决方案 »

  1.   

    你的sql語句和你講的邏輯對不上啊
    到底是
    条件二)表A中的id 不在表B的查询条件(select B.id from B where B.content is not null)
    還是存在與 表B的查询条件(select B.id from B where B.content is not null)?我就按照不存在好了
    select
      (select row_number() over (order by a.id) rown, A.* 
      from A,B 
      where a.id=b.id(+) and b.id is null)
    where
    rown<=20 and rown>=10
    如果是存在那麽
    select
      (select row_number() over (order by a.id) rown, A.* 
      from A,B 
      where a.id=b.id)
    where
    rown<=20 and rown>=10
      

  2.   

    應該是rown<=20 and rown>10
    上面的語句更換一下,沒有後面的“=”號
      

  3.   

    yqwd911(windy) 你是对的!谢谢指教!