insert into @t select '1001', '现金科目', '1001'
union all select '10010', '人民币' , '1001'
union all select '1002' , '银行存款', '1002'
--解决方法
select * from @t a
where subid<>parentid
or subid=parentid
and not exists(select * from @t b
where b.subid<>b.parentid and a.subid=b.parentid)