员工编号  姓名    年龄    上司编号
id         name   age     mid 
求所有员工年龄大于上司年龄的记录(上司也是员工)

解决方案 »

  1.   


    select id,name,age,mid from 
    (
    select a.id ,a.name,a.age,a.mid ,b.id as bid,b.name as bname,b.age as bage,b.mid  as bmid from table a inner join table b on a.mid=b.id)
    where age>bage
      

  2.   

    sql="select age from table_name where id=上司_id";
      

  3.   

    create table t(id int,age int,mid int);
    insert into t values(1,2,0);
    insert into t values(2,3,1);
    insert into t values(3,1,1);
    insert into t values(4,2,2);
    insert into t values(5,12,4);
    insert into t values(6,1,3);
    insert into t values(7,32,2);SQL> select t2.id from t t1,t t2 where t1.id=t2.mid and t2.age>t1.age;
     
                                         ID
    ---------------------------------------
                                          2
                                          5
                                          7
      

  4.   

    楼上正解,其实也可以写成
    select  (case when 
    t2.age>t1.age
    then t2.id
    end)id
    from t t1,t t2 where t1.id =t2.mid