日期:2014-05-18  浏览次数:20461 次

将一个表中有一列为fatherID,我想把fatherID相同的数据作为一个临时表输出。输出过个表。
将一个表中有一列为fatherID,我想把fatherID相同的数据作为一个临时表输出。输出过个表。

------解决方案--------------------
给出具体测试数据和结果
------解决方案--------------------
探讨
将一个表中有一列为fatherID,我想把fatherID相同的数据作为一个临时表输出。输出过个表。

------解决方案--------------------
SQL code

select *
from tb
where fatherid in (
    select fatherid
    from tb
    group by fatherid
    having count(*) > 1
)

------解决方案--------------------
SQL code

--存在主键字段,假设为Id

select *
from tb t
where exists (select 1 from tb where fatherid=t.fatherid and id<>t.id)