select * from t1 
where exists ( select 1 from t2 
                where t1.staffID=t2.staffID
                  and nvl(t1.sumcode,0) > nvl(t2.maxcost,0))

解决方案 »

  1.   

    select t1.* from t1,t2
    where t1.staffid=t2.staffid and t1.sumcost>t2.sumcost;
      

  2.   

    select t1.* from t1,t2
    where t1.staffid=t2.staffid and t1.sumcost>t2.sumcost;
      

  3.   

    PL/SQL Developer中高亮 然后 F5
      

  4.   

    select * from table1 t1 where exists(select 1 from table t2 where t2.staffID=t1.staffID and t2.maxCost<t1.sumCost)
      

  5.   

    select t1.* from t1,t2
    where t1.staffid=t2.staffid and t1.sumcost>t2.sumcost;
    这个吧
      

  6.   

    select t1.* from t1,t2
    where t1.staffid=t2.staffid and t1.sumcost>t2.sumcost;
    这个简单易懂
      

  7.   

    select * from t1 
    where exists ( select 1 from t2 
                    where t1.staffID=t2.staffID
                      and nvl(t1.sumcode,0) > nvl(t2.maxcost,0))
    我不懂啊!
    这个select 1 from t2是什么意思啊?
    谢谢大哥解释一下啊!
      

  8.   

    不需要考虑为空的情况吗?
    nvl(t1.sumcode,0) > nvl(t2.maxcost,0))
    这样还是更保险吧
      

  9.   

    select 
        a.* 
    from 
        t1 a
    left join
        t2 b
    on
        a.staffID = b.staffID and nvl(a.sumCost,0) > nvl(b.maxCost,0)
      

  10.   

    select t1.* from t1,t2
    where t1.staffid=t2.staffid and t1.sumcost>t2.sumcost;不能选出 005     a1550 这条记录,需要用左连结select t1.* from t1,t2
    where t1.staffid+=t2.staffid and t1.sumcost+>t2.sumcost;
    自己试一下吧
      

  11.   

    楼上的
    005     a1550 这条记录的staffid是a1,不会选不出的