表1名称 数据 类别
1    789  a
2    123  a
3    339  a
1    339  b
2    666  b
3    888  b
1    336  c
2    666  c
3    777  c如何选出表1数据列里重复的数据 谢谢
上面例子得结果名称 数据 类别
3    339  a
1    339  b
2    666  b
2    666  c

解决方案 »

  1.   

    declare @t table(名称 int, 数据 int, 类别 varchar(2)) 
    insert @t select 1,    789,  'a' 
    insert @t select 2,    123,  'a' 
    insert @t select 3,    339,  'a' 
    insert @t select 1,    339,  'b' 
    insert @t select 2,    666,  'b' 
    insert @t select 3,    888,  'b' 
    insert @t select 1,    336,  'c' 
    insert @t select 2,    666,  'c' 
    insert @t select 3,    777,  'c'
    select * from @t where 数据 in( select   数据 from @t group by  数据 having count(*)>1)
    /*名称          数据          类别   
    ----------- ----------- ---- 
    3           339         a
    1           339         b
    2           666         b
    2           666         c*/
      

  2.   


    select * from t
    where exists(select 1 from t as aa where aa.名称 = t.名称)
    and
    exists(select 1 from t as aa where aa.数据 = t.数据)
    and
    exists(select 1 from t as aa where aa.类别 = t.类别) order by t.数据
      

  3.   

    select * from tb where 数据 in (select 数据 from tb group by 数据 having count(*)>1)3 339 a
    1 339 b
    2 666 b
    2 666 c
      

  4.   


    select * 
    from tb a 
    where (select count(1) from tb where 数据=a.数据)>=2
      

  5.   

    /**
    名称 数据 类别 
    3    339  a 
    1    339  b 
    2    666  b 
    2    666  c
    **/