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
sql="select age from table_name where id=上司_id";
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
楼上正解,其实也可以写成 select (case when t2.age>t1.age then t2.id end)id from t t1,t t2 where t1.id =t2.mid
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
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
select (case when
t2.age>t1.age
then t2.id
end)id
from t t1,t t2 where t1.id =t2.mid