try:select * from ( select * from table1 where id in(select parent_id from table1)) where id in ( select parent_id from table1 where id in(select parent_id from table1) );
select B.id from 表名 A,表名 B where A.parent_id = B.id
上面按错了select B.parent_id from 表名 A,表名 B where A.parent_id = B.id
试试这个。。 select * from tablename where id in(select distinct parent_id from table where id in(select distinct parent_id from tablename))
针对这种情况,db2中有with,oracle中有start with 你不会以为IBM和oracle都疯了,没有用的东西也加到数据库上?
呵呵,很有意思,看看我这个select id,name from table_name a where exists (select id from table_name b where b.parent_id = a.id and exists (select id from table_name c where c.parent_id = b.id));
IBM内部的项目,很多在数据库中用的就是这种存储方式,我看你真不用说了。
select t.id,t.name from table t where t.id in(select count(*) as num from table a group by parrentid where num>2) 这个行不
select t1.* from table1 t1, (select ParentID from table1 t2 where exists(select t3.ID from table1 t3 where t3.ParentId=t2.ID)) t4 where t1.ID=t4.ParentID;
select a.id,a.name from table a,table b,table c where a.id=b.parent_id and b.id=c.parent_id;
select t1.parent_id from table t1 where t1.id in (select t2.parent_id from table t2 where t2.id is not null) 这样对么?
select * from table1 where id in(select parent_id from table1)) where id in (
select parent_id from table1 where id in(select parent_id from table1) );
from 表名 A,表名 B
where A.parent_id = B.id
from 表名 A,表名 B
where A.parent_id = B.id
select * from tablename where id in(select distinct parent_id from table where id in(select distinct parent_id from tablename))
你不会以为IBM和oracle都疯了,没有用的东西也加到数据库上?
where exists (select id from table_name b
where b.parent_id = a.id
and exists (select id from table_name c where c.parent_id = b.id));
IBM内部的项目,很多在数据库中用的就是这种存储方式,我看你真不用说了。
(select ParentID from table1 t2 where exists(select t3.ID from table1 t3 where t3.ParentId=t2.ID)) t4
where t1.ID=t4.ParentID;
这样对么?
这个在IBM面试里面应该不算是什么复杂问题。