现有一表Tb…其中含有字段Xm,csrq(姓名,出生日期,都是字符型),现在想将姓名和出生日期重复的记录找出来…不知道怎么写…求教…谢谢…我写了个Ms不对Select * from tb where xm in (select xm from tb group by xm having count(xm)>1) and csrq in (select csrq from tb group by csrq having count(csrq)>1) order by csrq

解决方案 »

  1.   


    select xm,csrq,count(*) from tb group by xm,csrq having(count(*)>0);
      

  2.   


    --呵呵 上面错了,是>1
    select * from tb group by xm,csrq having(count(*)>1);
      

  3.   

    select xm,csrq,count(*) from tb group by xm,csrq having(count(*)>1);
      

  4.   

    楼上几位都没理解我所表达的意思…比如说人员a有重复记录…我要把所有人员a的记录都查出来才可以…而不是只显示一条人员a…
      

  5.   


    with tab as (
    select t.*, count(1) over (partition by xm,csrq) cnt from tb t
    )
    select * from tab where cnt>1;
      

  6.   

    SELECT XX.* FROM (
    SELECT Xm,csrq,COUNT(*)OVER(PARTITION BY Xm,csrq) R FROM TAB
    ) XX
    WHERE XX.R>1
      

  7.   

    Select * from tb a
    where (select count(*) from tb b where a.xm=b.xm and a.csrq=b.csrq)>1Select * from tb where (xm,csrq) in(select (xm,csrq) from tb group by xm,csrq having count(*)>1)
      

  8.   


    orselect * from (
    select a.*,count(*) over(partition by xm,csrq order by 1) cnt from tb a) where cnt>1