日期:2014-05-17  浏览次数:20470 次

如何过滤sql表中的两列或三列相同的数据行,显示的是相同的数据,不相同的不显示
如何过滤sql表中的两列或三列相同的数据行,显示的是相同的数据,不相同的不显示,注意如果有重复相同的,也需要把重复的显示出来,比如这个表,我需要查询出字段stuid和proid 相同的行数据

我打了一段代码

select stuid,proid
from scoreInfo
group by stuid,proid
having count(*) > 1

结果是

但是她把重复的过滤了,我需要把两列相同的行,即使是重复也显示出来

小弟第一次在论坛说话问题目,请各位高人大哥帮帮我,急求!今晚就需要,谢谢了

------解决方案--------------------

select a.*
 from scoreInfo a
 inner join
 (select stuid,proid
  from scoreInfo
  group by stuid,proid
  having count(*)>1) b on a.stuid=b.stuid and a.proid=b.proid

------解决方案--------------------
或者这样写,

select * from scoreInfo a
 where exists(select 1 from scoreInfo b 
              where b.stuid=a.stuid and b.proid=a.proid and b.id<>a.id)