当前位置: 代码迷 >> Sql Server >> 将一个表中有一列为fatherID,小弟我想把fatherID相同的数据作为一个临时表输出。输出过个表
  详细解决方案

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

热度:6   发布时间:2016-04-27 13:51:48.0
将一个表中有一列为fatherID,我想把fatherID相同的数据作为一个临时表输出。输出过个表。
将一个表中有一列为fatherID,我想把fatherID相同的数据作为一个临时表输出。输出过个表。

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

------解决方案--------------------
SQL code
select *from tbwhere fatherid in (    select fatherid    from tb    group by fatherid    having count(*) > 1)
------解决方案--------------------
SQL code
--存在主键字段,假设为Idselect *from tb twhere exists (select 1 from tb where fatherid=t.fatherid and id<>t.id)