select a.*,b.* from Table1 a,Table2 b where a.type=b.typeId and a.amount>b.offset

解决方案 »

  1.   

    zhangxhsj(泡泡龙) 兄的方法不能保证只有一条。就上面的情形如果amount=8显然有两条
      

  2.   

    select * from (select a.*,b.* from Table1 a,Table2 b where a.type=b.typeId and a.amount>b.offset) where rownum<=1
      

  3.   

    beckhambobo(beckham)兄误解我的意思了
    我希望的结果是如果table1{1,1,8} table2{1,0;1,7;1,14} 返回{1,1,8,1,7}
    如果table1{1,1,8;2,1,15}返回{1,1,8,1,7;2,1,15,1,14},不是说一共只有一条,而是对table1的每条数据在table2找到的匹配项是1条或没有
      

  4.   

    从你的说明中,是指typeId(pk),offset(pk)是primery key,对吧,如果这样,可以这样做:
    SELECT * 
    FROM TABLE1 t1,TABLE2 t2 
    WHERE t1.TYPE = t2.typeid
    AND t1.amount > t2.offsert
    AND t2.offsert = (
          SELECT MAX(t3.offsert) AS max_offset 
      FROM TABLE2 t3
          WHERE t3.offsert < t1.amount
      AND t3.typeid = t1.TYPE
     );
      

  5.   

    Sorry,刚才的发文我把offset写错写成了offsert.--我测试了,应该没有问题
      

  6.   

    select * 
      from (select a.*,b.* 
              from Table1 a,Table2 b 
             where a.type=b.typeId and a.amount-1=b.offset) 
    where rownum<=1
    这样不知道是不是你的意思
      

  7.   

    wwl007(疑难杂症) :
    应该还不是.:P